The Matlab function rand returns a uniformly distributed random number between 0 and 1. Uniformly distributed means it’s just as likely to return 0.002 as it is 0.928. The two most common usages are passing either one or two variables. If one variable, say N, is passed, Matlab will return an N x N array of random numbers. If two variables are passed, say N and M, it will return an array of size N x M.
Here’s an example:
>> rand(3) ans = 0.498945 0.088035 0.667322 0.903201 0.554317 0.231287 0.472007 0.432178 0.740403 >> rand(3,2) ans = 0.032335 0.626125 0.610221 0.395778 0.783036 0.953567
If you wanted a column of random numbers, you could simply assign x = rand(N,1), where N is the number of elements you want in your array (or column). Continue reading »
