The evolution together -matlab basic calculation functions inf, isempty, round
Find useful, welcome to discuss mutual learning together - Follow Me
inf
- in matlab inf infinity '+ ∞, -inf is infinitesimal quantity -∞, when Matlab program execution, even in the face of a zero-divisor operation, it will not terminate the program running, but only to give a "divide by zero" Warning and assigns the result to inf, to continue
isempty
Decide whether an array is empty
description
If A is an empty array, then return isEmpty TF = (A) a logical 1 (true), otherwise a logical 0 (false). Empty array has a size of at least zero dimensions.
round
Rounded to the nearest decimal point or integer
description
- Y = round (X) of each element X, rounded to the nearest integer
- Y = round(X,N)
- Y = Integer (X, N) rounded to N bits:
- N> 0: N rounded to the right of the decimal place.
- N = 0: rounding to the nearest integer.
- N <0: N bits to the left of the decimal point are rounded.
- Y = round (X, N, type) specifies the type of rounding. Specify "significant" rounding to N bits of significant digits (counting from the left-most digit). In this case, N must be a positive integer.
- Y = round (t) the duration of each element of the array t is rounded to the nearest second.
Y = round (t, unit) t of each element of rounded to the nearest specified number of time units.
Examples
X = [2.11 3.5; -3.5 0.78];
Y = round(X)
Y =
2 4
-4 1
% 四舍五入到指定的小数位数
Y = round(pi,3)
Y =
3.1420
% 四舍五入到最接近100的倍数
round(863178137,-2)
ans =
863178100
The elements rounded to the specified number of significant digits
The elements of the vector rounded to two significant digits reserved
x = [1253 1.345 120.44]
y = round(x,2,'significant')
x =
1253 1.345 120.44
y =
1300 1.3 120
Rounded to time
The duration of each value in the array are rounded to the nearest second
t = hours(8) + minutes(29:31) + seconds(1.3:0.5:2.3);
t.Format = 'hh:mm:ss.SS'
t =
08:29:01.30 08:30:01.80 08:31:02.30
Y1 = round(t)
Y1 =
08:29:01.00 08:30:02.00 08:31:02.00
Round each value in t to the nearest number of hours.
Y2 = round(t,'hours')
Y2 =
08:00:00.00 09:00:00.00 09:00:00.00