This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Evaluation – 1”.
1. What is the output of the following code?
b) Logical Error
c) Symbolic error
d) No output
Explanation: As eval evaluates the MATLAB expression in the input, it will evaluate the input to 23 and assign it to q. There are no errors in the above code.
2. What is the output of the following code?
a) Unexpected MATLAB expression
q = 23 r = 45
d) Error due to eval
Explanation: The eval command returns an error if more than a pair of inverted commas are found. Hence, unexpected MATLAB expression is correct option. Option q=23,r=45 cannot happen since 23 and 45 will be stored in a single character array.
3. What is the output of the following code?
c) Syntactical error
d) The eval command does not exist
Explanation: An input to the eval command will have to be within a pair of inverted commas. Here, we haven’t used them so MATLAB will return an error.
4. What is the output of the following code?
a) No such command
d) ‘ ans=1 ’
Explanation: Evalc takes the entire output of the input expression into a string. Hence, it will show a as an answer were the entire thing will be shown, within, as a string.
5. What is the size of p from the following code?
a) 2 bytes
b) 0 bytes
d) 6 bytes
Explanation: The evalc command results in an empty character array. Hence, the size of p will be 0 but it’s class will be char.
6. The for keyword can be used to evaluate expressions using eval().
Explanation: Reserved keywords cannot be used explicitly in the eval() command. But they can be used by mentioning a function which is defined to use a for loop.
7. The evalc function is different from the eval command ________
a) no difference
b) from precision of output
c) from nature of output
d) from display of output
Explanation: The entire output is displayed as a character array using evalc while the eval command displays the output itself. There is no difference in precision or nature of output.
8. What is common to evalc and the eval commands, apart from the output?
a) The error message is displayed separately
b) The outputs are of different accuracy
c) There is nothing common
d) evalc does not exist
Explanation: The error messages, if any error, pertaining to the input expression, occurs, are displayed separately by both the command.
9. What is the output of the following code?
a) P= ‘ ’
b) P will be an empty character array
d) No such function
Explanation: We have assigned the output of the eval command to an expression. Hence, we will have to give an expression within ‘’ which results into any value. Here, we haven’t provided any expression so the statement in not complete. Hence, MATLAB returns an error.
10. What is the output of the following code?
a) Syntactical error
b) Logical Error
Explanation: There is no error in the following code. The string input to the feval command can also be given within ‘’. Hence, the final output is 1235.
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.