# MATLAB Questions and Answers – User Input and Screen Output – 1

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “User Input and Screen Output – 1”.

1. What is the output of the following code?

`error(“Lola !”);`

a) Output is suppressed
b) Syntactical error
c) No such function exists
d) It displays Lola !

Explanation: The input to the error command should be in ‘’ but here, “” was used which results in a syntactical error.

2. What is the output of the following code?

`error(‘Dan !’);`

a) No output, it gets suppressed
b) The word Dan ! is displayed
c) No such function
d) Syntactical Error

Explanation: The output won’t get suppressed due to the ; since this command is used to display the input given to it. There is no syntactical error.
Output: Dan !

3. What is the output of the following code?

`error(‘ No !!!!’)`

a) No !!!!
b) No !!!!
c) Logical Error
d) Symbolic error

Explanation: The input to the error() command will be displayed in red. This is in contrast to the disp() command and hence option No !!!! is correct.
Output: No !!!!

4. What is the output of the following code?

`error(‘Lola ! \n Dan !’);`

a) Output is suppressed
b) Symbolic error in \n
c)

```    Lola !
Dan !```

d) Lola ! \n Dan !

Explanation: We can give multiple input to the error() command. But the ‘\n’ character on;y works if we give multiple input like error(‘String argument e.g. ‘Lola ! \n Dan !’ , 1Arg, 2Arg..) where 1Arg, 2Arg are different variables which gets displayed due to the error() command itself. If that’s the case, the output would have been option c. But here we have only 1 string argument and so the \n character won’t work.
Output: Lola ! \n Dan !

5. What is the output of the following code?

`MException('Lola!', '%d * %d= Why?', Inf,Inf)`

a) Error due to identifier
b) Error due to Inf
c)

```    MException with properties:
identifier: 'Lola!’
message: 'Inf * Inf= Why?'
cause: {}
stack: [0×1 struct]```

d) No such command

Explanation: The message identifier, ‘ Lola !’ given as an input to the MException command is not a valid MATLAB identifier. There is a set of valid identifiers and any input other input will give an error.

6. What is the output of the following code?

`MException('MATLAB:test', '%d * %d= Why?', Inf,Inf)`

a)

```    MException with properties:
identifier: ‘MATLAB:test’
message: 'Inf * Inf= Why?'
cause: {}
stack: [0×1 struct]```

b)

```    MException with properties:
identifier: “MATLAB:test”
message: 'Inf * Inf= Why?'
cause: []
stack: [0×1 struct]```

c)

```    MException with properties:
identifier: ''MATLAB:test’
message: '%d * %d= Why?'
cause: {}
stack: [0×1 struct]```

d) Error

Explanation: %d would get converted to the value given as an argument after the message input in the MException command. The cause is not specified so it would remain a cell array, identified by {}. The identifier is shown within a ‘’ and not “”.There is no error in the code.
Output:

```    MException with properties:
identifier: ‘MATLAB:test’
message: 'Inf * Inf= Why?'
cause: {}
stack: [0×1 struct]```

7. What is the output of the following code?

`disp(‘%d’,Inf);`

a) Inf
b) No such command
c) Error due to too many arguments
d) Syntactical error

Explanation: The disp command takes a maximum of 1 argument which is a string argument only. Hence it will return an error due to the second argument, Inf, given to it.

8. What is the output of the following code?

`sprintf(‘%d’,5)`

a) 5
b) ‘5’
c) Syntactical error
d) Logical error

Explanation: The sprint() command will convert the argument variables given to it into the format specifier mentioned as an input. But, the new value output of the sprint command will be assigned to a variable, here it’ll be the ans variable, which will be a string variable.

9. What is the output of the following code?

`warning(‘Pikapi !’)`

a) Warning: ‘Pikapi !’
b) Warning: Pikapi !
c) Warning: ‘Pikapi !’
d) Warning: Pikapi !

Explanation: A warning message is always displayed in a dark yellow color. The message itself is not shown as contained within a ‘’. Hence, option Warning: Pikapi ! is correct.
Output: Warning: Pikapi !

10. What is the output of the following code?

```warning('off')
warning('Pikapi !')```

a) No output
b) Warning: Pikapi !
c)

```    Warning: Off
Warning: Pikapi !```

d) Syntactical error

Explanation: No warning message will be displayed by MATLAB since we’ve disabled the working of the warning() command itself with working(‘off’). We can again enable it by simply writing warning(‘on’).

11. What is the output of the following code?

`disp(‘ ‘,lola!’ 2’)`

a) ‘lola!’ 2
b) ‘ ‘lola!’ 2’
c) ‘lola! 2’
d) Error due to multiple arguments

Explanation: Within the ‘’, when we’re giving input to the disp command, the we cannot include another set of ‘’. This will given an error. The next set of ‘’ will be treated as an extra character argument while the first set of ‘’ will close itself once we give a ’ for our first set of single-inverted commas. This means, in the above command, after disp(‘ ‘..) the input argument is already taken as a space character by the command while starting from lola.. the entire thing is another argument.

12. How many arguments are given to the above command?

`disp(‘ ‘lola!’ 2’)`

a) Cannot be defined
b) 2
c) 1
d) 0

Explanation: The syntax of the disp() command is disp(string argument). To introduce further arguments, we habe to use disp(string argument,1Arg,2Arg). Now, once we end our string argument, we need to put a comma. Here, we haven’t put any comma so it shows that there is only 1 string argument while the rest is not defined as an argument also.

13. What is the output of the following command?

`sscanf(‘.1 .2 .3’,%d)`

a) []
b)

```
.1
.2
.3```

c)

```
1
2
3```

d) Error

Explanation: The input contains a string of floating point variables but the format specifier is for integer type.

14. The default exponential order for %e and %E is same.
a) True
b) False

Explanation: %e will signify the exponential order as e while %E will signify it as E. But the default order of representation of both of them is same.

15. The disp() command cannot print anything but inputs given within string arguments.
a) True
b) False 