Rounding The Numbers And Matrix Elements In MatLab(Illustrated Expression)

In this article of Mechanical Base, we will show how to round the numbers or variables to upper or lower values in Matlab. It is very useful command in Matlab that you can utilize from when you need to do your calculations upon the integers. Look at the examples below in Matlab and see how to do it.

How To Round The Numbers, Matrices Or Vectors In MatLab?

Use of different rounding commands such as ‘round()’, ‘ceil()’, ‘floor()’ in Matlab.

You can use ‘round()’ command to round a number or matrix etc. to the closest integer element by element in Matlab.

The number of 5.55 is rounded to 6 with round() command in Matlab, because 6 is the closest integer to 5.55.

Also the same process is done to b vector elements and c matrix elements separately with round() command as shown by green and red arrows above in Matlab.

Also you can use the floor() command in Matlab to round the decimal numbers to closest lower integer. As you can see with yellow arrow above, the number of 3.33 is rounded to lower integer value of 3 with floor() command.

And ceil() command can be used to round the decimal number to closest upper integer in Matlab. The number of 5.55 is rounded to 6 with ceil() command as shown by orange arrow above. 6 is the closest upper integer to 5.55.

So it is very basic to round the decimal numbers in Matlab with different codes such as round(), ceil() and floor().

Share This Post! Share Tweet Share

Write your comment on this topic.