In Matlab, you can obtain various kinds of matrices by using also various kinds of commands. Also, you can obtain even a matrix that comprises randomly obtained elements inside it. This command generates random element matrices called the ‘rand’ command. The use of the ‘rand’ command is very easy. We gave basic examples below so that you can understand how to use the ‘rand’ command in Matlab and which kinds of matrices in Matlab by using the ‘rand’ command. Generating random matrices in Matlab is very simple.

**Check: Recommended Books to Learn Matlab®**

## How to Use Rand Command in Matlab®?

(Illustrated Expression)

```
>> v = rand(3,5)
z = 5.*v
d = 5.*rand(5,6)
v =
0.8147 0.9134 0.2785 0.9649 0.9572
0.9058 0.6324 0.5469 0.1576 0.4854
0.1270 0.0975 0.9575 0.9706 0.8003
z =
4.0736 4.5669 1.3925 4.8244 4.7858
4.5290 3.1618 2.7344 0.7881 2.4269
0.6349 0.4877 4.7875 4.8530 4.0014
d =
0.7094 3.2787 3.7887 3.5302 4.1173 2.1937
2.1088 0.1786 3.7157 0.1592 3.4741 1.9078
4.5787 4.2456 1.9611 1.3846 1.5855 3.8276
3.9610 4.6700 3.2774 0.2309 4.7511 3.9760
4.7975 3.3937 0.8559 0.4857 0.1722 0.9344
>>
```

As you can see from the example above about the ‘rand’ command in Matlab®, the general use of it only typing rand then typing dimensions of the matrix inside parentheses right after it as at the variable v. You can see the variable v result that the 3×5 matrix that comprises randomly created numbers between 0 and 1.

Also, you could do mathematical calculations with random numbered matrices that you created with the ‘rand’ command in Matlab® as in the z variable above. You can see the result that the whole elements of the variable v matrix are simply multiplied with the number of 5.

Also, you can directly use the ‘rand’ command in Matlab® in mathematical calculations as in d variable. 5×6 dimensioned matrix is created via ‘rand’ command then this directly multiplied with the number of 5 as you can see from the result of variable d.

### Creating Random Arrays in Matlab

You can also create vectors and arrays in Matlab with random elements. You just need to enter the dimension of the array. Actually vector or array is the one dimension matrix. So, if you type 1 to the first elements of the rand() command in Matlab, you will have the array and vectors. Check the code example below.

```
r = rand(1, 5)
3.1472
4.0579
-3.7301
4.1338
1.3236
```

In this example, we try to create a vector that has 5 elements in Matlab. We typed 1,5 inside the rand() command and you can see the result above.

Above all, Matlab has very useful commands and tools to generate different kinds of matrices. Check the articles to see the abilities of Matlab matrix creation.

- Inverse of Matrix in Matlab®
- Sorting Elements of A Matrix Or Vector in Ascending and Descending Way on Matlab®
- Rounding The Numbers And Matrix Elements In Matlab®(Illustrated Expression)
- Addition of Diagonal Elements of a Matrix In Matlab®(Illustrated Expression)
- Determinant of a Matrix in Matlab®(Illustrated Expression)

## Conclusion

So you can obtain various kinds of matrices that comprise randomly created numbers in Matlab. You can use the rand() command in various kinds of calculations and applications in Matlab.

Do not forget to leave your comments and questions below about the generating random matrices in Matlab below.

If you want further coding examples about the ‘rand()’ command in Matlab®, inform us in the comments.

This article is prepared for completely educative and informative purposes. Images used courtesy of Matlab®

Your precious feedbacks are very important to us.