This set of MATLAB Interview Questions and Answers focuses on “Arithmetic – 2”.
1. Round each value in a duration array to the nearest number of seconds greater than or equal to that value.
t = hours(8) + minutes(29:31) + seconds(1.23); t.Format = 'hh:mm:ss.SS' t = 08:29:01.23 08:30:01.23 08:31:01.23 Y1 = ceil(t) Y2 = ceil(t,'hours')
Y1 = 08:29:02.00 08:30:02.00 08:31:02.00 Y2 = 09:00:00.00 09:00:00.00 09:00:00.00
Y1 = 08:29:02.00 08:30:02.00 08:31:02.00 Y2 = 08:29:01.23 08:30:01.23 08:31:01.23
Y1 = 08:29:01.23 08:30:01.23 08:31:01.23 Y2 = 08:29:01.23 08:30:01.23 08:31:01.23
Y1 = 008:29:01.23 08:30:01.23 08:31:01.23 Y2 = 09:00:00.00 09:00:00.00 09:00:00.00View Answer
Explanation: Y = ceil(t, unit) rounds each element of t to the nearest number of the specified unit of time greater than or equal to that element. Round each value in t to the nearest number of hours greater than or equal to that value.
2. What would be the output of the following code (in editor window)?
X = [1.4+2.3i 3.1-2.2i -5.3+10.9i] X = 1.4000 + 2.3000i 3.1000 - 2.2000i -5.3000 +10.9000i Y = fix(X)
a) Y = 1.0000 + 2.0000i 3.0000 – 4.0000i -5.0000 +10.0000i
b) Y = 2.0000 + 3.0000i 3.1000 – 2.2000i -5.3000 +10.9000i
c) Y = 1.0000 + 2.0000i 3.0000 – 2.0000i -5.0000 +10.0000i
d) Y = 2.0000 + 3.0000i 3.1000 – 2.2000i -5.3000 +10.9000i
Explanation: Y = fix(X) rounds each element of X to the nearest integer toward zero. For positive X, the behavior of fix is the same as floor. For negative X, the behavior of fix is the same as ceil.
3. Compute 24 modulo 5.
b = mod(24,5)
a) b = 3
b) b =4
c) b =5
d) b =6
Explanation: b = mod(a,m) returns the remainder after division of a by m, where a is the dividend and m is the divisor. This function is often called the modulo operation and is computed using b = a – m.*floor(a./m). The mod function follows the convention that mod(a,0) returns a.
4. What would be the output of the following code (in editor window)?
X = [1 2 3;4 5 6;7 8 9]; Y = [9 8 7;6 5 4;3 2 1]; R = rem(X,Y)
R = 1 2 1 4 0 9 1 0 0
R = 1 2 3 3 0 2 1 0 0
R = 1 2 3 4 1 2 1 1 0
R = 1 2 3 4 0 2 1 0 0View Answer
Explanation: R = rem(X,Y) returns the remainder after division of X by Y. In general, if Y does not equal 0, R = rem(X,Y) returns X – n.*Y, where n = fix(X./Y). If Y is not an integer and the quotient X./Y is within round off error of an integer, then n is that integer. Inputs X and Y must have the same dimensions unless one of them is a scalar double. If one of the inputs has an integer data type, then the other input must be of the same integer data type or be a scalar double.
5. If one operand is a scalar and the other is not, then MATLAB applies the scalar to every element of the other operand. This property is known as ______________
a) operand divergence
b) scalar expansion
c) vector expansion
d) dimension declaration
Explanation: If one operand is a scalar and the other is not, then MATLAB applies the scalar to every element of the other operand. This property is known as scalar expansion because the scalar expands into an array of the same size as the other input, then the operation executes as it normally does with two arrays.
6. Matrix operations follow the rules of linear algebra and are not compatible with multidimensional arrays.
Explanation: Matrix operations follow the rules of linear algebra and are not compatible with multidimensional arrays. The required size and shape of the inputs in relation to one another depends on the operation.
7. Conversion Function int16 uses_________ range of value?
a) -27 to 27-1
b) -215 to 215-1
c) -231 to 231-1
d) 0 to 216-1
Explanation: Conversion Function int16 having class of signed 16-bit integer. And signed 16-bit integer follows -215 to 215-1 range.
8. Largest and smallest values for integer classes is 127 to -128.
Explanation: Obtain these values with the intmax and intmin functions:
ans = 127
ans = 128.
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB for Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.
Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!