MATLAB Questions and Answers Part-9

1. What is the nature of storage of anything in MATLAB?
a) Stored as arrays
b) Stored as a data structure
c) Stored as a variable
d) Depends on nature of the input

Answer: a
Explanation: An array is a data structure. But, even a single variable in MATLAB is stored as a 1*1 array. Every variable we use in MATLAB is stored as an array.

2. What is the nature of the following variable, in MATLAB?
A=[1 , ‘Poland’, ‘Nail polish’,’Hit’,’Ler’]
a) String
b) String-integer
c) Integer-string
d) Cannot be determined

Answer: a
Explanation: MATLAB will take the variable A as a string variable. It will replace the 1 with an unknown value.

3. What is the starting index of an array in MATLAB?
a) 1
b) 0
c) Depends on the class of array
d) Unknown

Answer: a
Explanation: Unlike C, the starting address of an array in MATLAB is 1. Hence if we declare an array named arr and type arr(0), we will get an error. The first entry to the array will have the index 1.

4. All data types are converted to ____ before mathematical operations.
a) Single
b) Double precision
c) Floating
d) Unsigned

Answer: b
Explanation: All mathematical operations are done with double precision in MATLAB. Hence, all data types, single and floating, are converted to double data types.

5. What is the return type of angles in MATLAB?
a) Degrees
b) Radians
c) Radians & Degrees
d) Depends on the user

Answer: b
Explanation: This is characteristic of MATLAB to take input for angles and return angles in radians. Thus entering sin(90) in MATLAB will not return 1, but entering sin(pi/2) will return 1.

6. To represent only two digits after the decimal point, the format we use is ______
a) Long e
b) Short
c) Hex
d) Bank

Answer: d
Explanation: The Long e format is used to represent a total of 15 digits while short is used to represent 4 digits after decimal. The formal Hex is used for the hexadecimal representation of bits. The bank format is also called ‘Dollars and Cents’. It is used to display only two digits after the decimal.

7. How do we change the nature of the display of the numerical answer?
a) Use the format command
b) Use the class command
c) MATLAB provides intuitive display
d) Not possible

Answer: a
Explanation: The format command is used to change the display of numerical answer. If the format command is not invoked, MATLAB will always show four digits after decimal point and all the digits before the decimal point.

8. Strings are stored in ____ variables.
a) Character
b) String
c) Stack
d) Array

Answer: a
Explanation: All the variables are stored in the form of arrays. So strings are also stored as character variables. The variables are not called string variables.

9. What will be the output of the following code?
ilaplace(1/syms p^2)
a) t
b) s
c) error
d) ilaplace is not present in MATLAB

Answer: c
Explanation: We need to declare p as a symbolic variable before passing it to the ilaplace command. But here, MATLAB won’t show that p is not defined. It will show ‘Unexpected MATLAB expression’ since the command ilaplace is defined to accept variables already defined. It won’t allow defining a variable in the function parameter itself.

10. What is the output of the following code?
format bank
sym(sqrt(3))
a) 1.72
b) 1.73
c) 3(1/2)
d) sqrt(3)

Answer: c
Explanation: sym is used to represent the input arguments of the command in a symbolic form. Hence, MATLAB won’t evaluate the value of the square of 3. It will represent it symbolically as 3(1/2).