# Creating Random Numbers In MatLab

In some cases, you must use randomly created numbers in your codes in Matlab. To do it, you can use ‘rand()’ command in Matlab to obtain matrices and vectors that has randomly created numbers inside their elements. In here, we explain how to use ‘rand()’ command in Matlab.

## How To Use ‘rand()’ Command In MatLab?

``````>> rand(6)
%first example
rand(3,6)
%second example
a = 10.*rand(1)
%third example

ans =

0.1190    0.7513    0.5472    0.8143    0.6160    0.9172
0.4984    0.2551    0.1386    0.2435    0.4733    0.2858
0.9597    0.5060    0.1493    0.9293    0.3517    0.7572
0.3404    0.6991    0.2575    0.3500    0.8308    0.7537
0.5853    0.8909    0.8407    0.1966    0.5853    0.3804
0.2238    0.9593    0.2543    0.2511    0.5497    0.5678

ans =

0.0759    0.7792    0.5688    0.3371    0.3112    0.6020
0.0540    0.9340    0.4694    0.1622    0.5285    0.2630
0.5308    0.1299    0.0119    0.7943    0.1656    0.6541

a =

6.8921
``````

The use of ‘rand()’ command to produce random numbers in Matlab is very simple. As you see in the first example of the use of ‘rand()’ command above, we created 6×6 matrix as you see at first answer in command window. The numer of ‘6’ creates 6×6 matrix that has randomly created elements inside it.

YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!

In second example, 3×6 matrix is created. So the numbers ‘3’ and ‘6’ means, 3×6 matrix creation in Matlab, which has randomly created elements inside it.