How to Round toward negative infinity in MATLAB
Rounding a number towards infinity means rounding the number X to the nearest integer less than or equal to X. In this article, we will discuss how to round toward negative infinity in MATLAB.
Suppose X = 3.5, then result is 3
And if X = -3.5, then result is -4
The floor() function in MATLAB can be leveraged to round the number towards negative infinity. Different syntaxes of floor() function in Matlab are
- Y = floor(val)
- Y = floor(X)
- Y = floor(t)
- Y = floor(t,unit)
Now we will discuss the syntaxes of the above function:
Y = floor(val):
- Rounds the element val to the nearest integer less than or equal to val.
Y = floor(X):
- The function takes input as a vector of elements X.
- Returns the vector by rounding each element in X toward negative infinity.
-2 -1 -5 7 -12
Y = floor(t):
- Here t is an array of duration in “hh:mm:ss:SS”
- hh: Hours
- mm: Minutes
- ss: Seconds
- SS: Milliseconds
- Rounds every element of array t to its nearest number of seconds less than or equal to the element.
duration : 05:02:01.78 05:03:01.78 05:04:01.78 Rounded duration : 05:02:01.00 05:03:01.00 05:04:01.00
Y = floor(t,unit):
- Here t is the duration array where every element in the format of “hh:mm:ss:SS”
- Rounds each element of t to the nearest number of the specified unit of time less than or equal to that element.
- Unit of time can be ‘seconds’, ‘minutes’, ‘hours’, ‘days’, or ‘years’.
- The default value of unit is ‘seconds’.
duration : 05:02:01.78 05:03:01.78 05:04:01.78 Rounded duration : 05:02:00.00 05:03:00.00 05:04:00.00