MATLAB Questions and Answers – Arithmetic – 2

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')

a)

     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
advertisement
advertisement

b)

     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

c)

     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
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

d)

     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.00
View Answer
Answer: a
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)?

advertisement
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
View Answer

Answer: c
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.

advertisement
b = mod(24,5)

a) b = 3
b) b =4
c) b =5
d) b =6
View Answer

Answer: b
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)

a)

   R = 1     2     1
       4     0     9
       1     0     0

b)

   R = 1     2     3
       3     0     2
       1     0     0

c)

   R = 1     2     3
       4     1     2
       1     1     0

d)

   R = 1     2     3
       4     0     2
       1     0     0
View Answer
Answer: d
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
View Answer

Answer: b
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.
a) true
b) false
View Answer

Answer: a
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
View Answer

Answer: b
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.
a) True
b) False
View Answer

Answer: a
Explanation: Obtain these values with the intmax and intmin functions:
intmax(‘int8’)
ans = 127
intmin(‘int8’) –
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.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.