We have moved to @ Placement Papers Hub !! Visit our new website here for more..

rand( ),randn( ) Matlab Functions


1)rand() Matlab Function

r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1).

r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix.

r = rand(m,n,p,...) or r = rand([m,n,p,...]) returns an m-by-n-by-p-
by-... array.

r = rand returns a scalar.

r = rand(size(A)) returns an array the same size as A.

*r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1).

>> R=rand(3)

R =

    0.8147    0.9134    0.2785
    0.9058    0.6324    0.5469
    0.1270    0.0975    0.9575

>> S=rand(3,2)

S =

    0.9649    0.9572
    0.1576    0.4854
    0.9706    0.8003


2)randn() Matlab function

 *r = randn(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard normal distribution.

*r = randn(m,n) or r = randn([m,n]) returns an m-by-n matrix.

*r = randn(m,n,p,...) or r = randn([m,n,p,...]) returns an m-by-n-by-p-by-... array.

*r = randn returns a scalar.

*r = randn(size(A)) returns an array the same size as A.


>> R=randn(8)

R =

   -0.2050    1.6302   -1.1471   -1.7115    0.6277    1.5326    1.1006    0.7481
   -0.1241    0.4889   -1.0689   -0.1022    1.0933   -0.7697    1.5442   -0.1924
    1.4897    1.0347   -0.8095   -0.2414    1.1093    0.3714    0.0859    0.8886
    1.4090    0.7269   -2.9443    0.3192   -0.8637   -0.2256   -1.4916   -0.7648
    1.4172   -0.3034    1.4384    0.3129    0.0774    1.1174   -0.7423   -1.4023
    0.6715    0.2939    0.3252   -0.8649   -1.2141   -1.0891   -1.0616   -1.4224
   -1.2075   -0.7873   -0.7549   -0.0301   -1.1135    0.0326    2.3505    0.4882
    0.7172    0.8884    1.3703   -0.1649   -0.0068    0.5525   -0.6156   -0.1774

>> S=randn(4,6)

S =
   -0.1961    1.5877   -0.2437    0.1049    0.1873   -1.7947
    1.4193   -0.8045    0.2157    0.7223   -0.0825    0.8404
    0.2916    0.6966   -1.1658    2.5855   -1.9330   -0.8880
    0.1978    0.8351   -1.1480   -0.6669   -0.4390    0.1001