# HELP with MATLAB: Compute distribution of 1000 random numbers

• Jun 3rd 2010, 10:17 AM
mchliakh
HELP with MATLAB: Compute distribution of 1000 random numbers
Hello,

I have to write a MATLAB program that:

A. Generates 1000 random digits (0-9).

B. Computes the distribution of these 1000 numbers.
Print out the dist., along with the mean and variance

I think I have the answer for A, which is this:

r = floor(10.*rand(1000,1));

But I can't seem to figure out B.

Can anyone help? Thanks in advance, any help is greatly appreciated.
• Jun 3rd 2010, 10:39 AM
CaptainBlack
Quote:

Originally Posted by mchliakh
Hello,

I have to write a MATLAB program that:

A. Generates 1000 random digits (0-9).

B. Computes the distribution of these 1000 numbers.
Print out the dist., along with the mean and variance

I think I have the answer for A, which is this:

r = floor(10.*rand(1000,1));

But I can't seem to figure out B.

Can anyone help? Thanks in advance, any help is greatly appreciated.

You need to count the number of 0s, 1s, 2s, ..., 9s. There are many ways of doing this but:

>sum(r==0)/1000

will return the proportion of 0s in the sample.

CB