Next Post:

How To Make Extrusion In Solidworks(Illustrated Expression)

How To Obtain Ones Matrices In MatLab®(Illustrated Expression)

In mathematical calculations in Matlab®, matrices are generally used. So there are lots of easy matrices generating commands in Matlab®. Sometimes users needed to obtain big matrices that include only the number of 1 in all elements inside it. This kind of matrix could be generated by a special command called ‘ones’. This is the command that the users could obtain matrices that comprises only the number ‘1’ inside them. You can follow the basic example below to understand how the ‘ones’ code works in Matlab®.

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

How The ‘Ones’ Is Used In Matlab®?

>> v = ones(2,3)
z = 5.*v
d = 5./ones(4,5)

v =

     1     1     1
     1     1     1

z =

     5     5     5
     5     5     5

d =

     5     5     5     5     5
     5     5     5     5     5
     5     5     5     5     5
     5     5     5     5     5


As you can see above, we gave three examples about the usage of the ‘ones’ command in Matlab®. The general use of the ‘ones’ command in Matlab® is like the v variable above. You just type ones then the dimensions of your matrix inside the parentheses right after it. You can see the v variable that includes only the number of 1 inside it.

Also, you can make mathematical calculations as shown with the z variable above. We just multiplied v with 5 then you can see all the numbers are multiplied with 5 in Matlab®.


Also, you can directly do mathematical calculations with ‘ones’ code as shown by the d variable. So you can obtain various matrices by using the ‘ones()’ command as shown above in Matlab®.

Do not forget to leave your comments and questions below about the use of the ‘ones()’ command in Matlab below. 

If you want further coding examples about ‘the ‘ones()’ 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.

  • Site Comments

At least 10 characters required.