# Matrices And Vectors With Randomly Created Elements In MatLab®(Illustrated Expression)

Like in every programming language, Matlab® has a command that creates a random number or numbers. But in Matlab®, you can create matrices and vectors that include randomly created elements inside it. In this article, we will show you how to create matrices or vectors whose elements are randomly created.

## How To Create Matrices And Vectors That Includes Random Elements In Matlab®?

``````>> a = rand(3,2)
b = rand(1,3)
5.*a
6.*b

a =

0.4898    0.7094
0.4456    0.7547
0.6463    0.2760

b =

0.6797    0.6551    0.1626

ans =

2.4488    3.5468
2.2279    3.7734
3.2316    1.3801

ans =

4.0782    3.9306    0.9757

>> ``````

Use of rand() command to create matrices and vectors in Matlab.

The ‘a’ is a matrice that created by random numbers as shown above in Matlab®. It is a 3×2 matrix as shown above and created with the rand() command.

Also, vector ‘b’ is a randomly numbered vector that is created by the rand() command again. Actually, it is a 1×3 matrix but also means it is a vector as shown above.

These ‘a’ matrix and ‘b’ vectors are multiplied with integers as shown by the red box above. Because rand() command in Matlab®, creates random numbers between 0 and 1. You can do multiplication as above to obtain a number between integers that you want. Multiplied vector and matrix could be seen above.

## Conclusion

The logic of creating matrices and vectors with rand() command in Matlab® is like that.