MATLAB Questions and Answers – Variables and Assignments

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Variables and Assignments”.

1. Which function is preferable to find the magnitude of a complex number?
a) abs()
b) sqrt()
c) cart2pol()
d) MATLAB does not support complex arguments
View Answer

Answer: a
Explanation: In the function sqrt(), we have to write the polynomial which shows the sum of squares of the real and imaginary part within the parentheses. But in abs(), we only have to enter the variable which we’ve used to define the complex number. So abs() is more preferred.
advertisement

2. Which is an escape sequence constant?
a) Esc
b) /n
c) \b
d) nargout
View Answer

Answer: c
Explanation: An escape sequence character constant is used in functions which are used to show output. ‘\b’ means backspace. ‘Esc’,‘/n’, are strings. ‘nargout’ is a pre-defined function in MATLAB.

3. All MATLAB computations are done in
a) Single Precision
b) Double Precision
c) Linear accuracy
d) Multi-level precision
View Answer

Answer: b
Explanation: MATLAB stores any integer variable as a double data type of 64 bits. For single precision, the function is ‘single()’ but if not mentioned, the value will be stored in double precision.

4. Which symbol is used to initialise a variable?
a) =
b) ->
c) ==
d) init
View Answer

Answer: a
Explanation: The symbol, ‘=’, is used to initialise a variable with a particular data type. ‘==’ checks whether the left hand side is equal to its’ right hand side. ‘init’ is a separate function in MATLAB.

5. Choose the correct option.
a) any() shows all the elements in a matrix while all() shows every element of a vector
b) any() is ‘true’ if elements in a vector is zero
c) all() is ‘true’ if every element in a vector is non zero
d) all() is ‘true’ if every element in a vector is 0
View Answer

Answer: c
Explanation: ‘any()’ and ‘all()’ are pre-defined functions in MATLAB. The function ‘any()’ returns 1 if every element of the vector, mentioned within the parentheses, is non-zero. The function ‘all()’ returns 1 if any element of the vector is non-zero.

6. What operator helps in the transpose of a matrix?
a) “ .’ ”
b) “ ‘ ”
c) “./ ”
d) “ .\ ”
View Answer

Answer: a
Explanation: ‘ .’ ‘ is used to get the transpose of a matrix. ‘ ‘ ‘ is used to get the complex conjugate transpose of a matrix. ‘ ./ ’ is used for the right division while the operator, ‘ .\’ is used for left division.
advertisement

7. What is the difference between the expressions (9*1-8) & (9-1*8)?
a) Computational difference
b) Final results are different
c) No difference
d) Cannot be determined
View Answer

Answer: a
Explanation: MATLAB follows a precedence of operators while doing any computation. So (9*1-8) is done like this: 9*1-8=9-8=9. But (9-1*8) is done like this: 9-1*8=9-8=1. Even though the answers are same, there is a computational difference between evaluation of the two expressions in MATLAB.

8. What is the output of the expression

(2*9*Inf)+(9-1*Inf)

a) Inf
b) Error
c) Incomprehensible
d) NaN
View Answer

Answer: d
Explanation: ‘NaN’ is a pre-defined variable in MATLAB. Whenever we try to evaluate an expression, if the expression contains sub-expressions which evaluate to infinity, the output produced is NaN. This denotes that the evaluation will not lead to number comprehensible by MATLAB.

9. The expression cos(90) is equal to1 in MATLAB.
a) True
b) False
View Answer

Answer: b
Explanation: Any argument within the parentheses of the functions ‘sin()’, ‘cos()’ are taken to be in radians. If the argument is to be processed in degrees, the function is modified as sind() and cosd().

10. Evaluate the expression:

advertisement
a=9/1*5/1;  b=a*a/a*a; c=sind(30)+1/2;  d=1-c; e=a+b*c-d

a) 2045
b) 2070
c) Error since sind() is a wrong function
d) 0
View Answer

Answer: b
Explanation: Following precedence of operators: ‘*’ > ’/’ > ‘+’ > ’–‘
a=9*5=45 ; b=a2/a*a=a*a=a2=2025 ; c=1/2+1/2=1 ; d=1-c=0 ;
e=45+2025*1-0=45+2025-0=2070-0=2070.
Output: 2070

Sanfoundry Global Education & Learning Series – MATLAB.

To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn