# MATLAB Questions and Answers – Evaluation – 1

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Evaluation – 1”.

1. What is the output of the following code?

`[q]=eval(sprintf('23 '))`

a) q=23
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?

`[q,r]=eval(‘sprintf('23 45')’)`

a) Unexpected MATLAB expression
b) q=23,r=45
c)

```   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?

`p=eval(cos(0));`

a) p=1
b)

```    p=
1```

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?

`evalc(‘cos(0)’)`

a) No such command
b) Error
c) 1
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?

`P=evalc(‘ ’)`

a) 2 bytes
b) 0 bytes
c) Error
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().
a) True
b) False

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?

`P=eval(‘ ’)`

a) P= ‘ ’
b) P will be an empty character array
c) Error
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?

`feval(“sum”,1234,1)`

a) Syntactical error
b) Logical Error
c) 1235
d) ‘1234’

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.
Output: 1235

Sanfoundry Global Education & Learning Series – MATLAB.

To practice all areas of MATLAB, 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]