This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Errors in Input – 2”.
1. What is the output of the following code?
isvector((49 32));
a) Error in ()
b) Error due to absence of comma
c) Error due to command
d) Logical 1
View Answer
Explanation: The input to the command isvector() should be placed within [] always. If the input is a single element, it can be placed within (). But since there are two elements, the above code will give an error.
2. What is the output of the following code?
clipboard('Do re Mi fa','copy')
a) Error in hierarchy
b) Copies the input text to the system clipboard
c) Replaces any text, in the clipboard, with the input text
d) Syntactical Error
View Answer
Explanation: The ‘copy’ input should be before the text which we want to copy to our system clipboard. Since it has been placed after the text, we get an error.
3. What is the output of the following code?
commandhistory[]
a) Error
b) Shows command history
c) Shows the previous command used
d) Prints all the commands used for the current session
View Answer
Explanation: We cannot give [] after the following command. We may give parentheses but it’s not needed though. Here, the output will be an error eventually.
4. What is the output of the following code?
pd=makedist('Uniform','Lower',3)
a) Error in giving limits
b) A uniform distribution with lower limit 3 and upper limit Infinity
c) Error in syntax
d) Error due to the command
View Answer
Explanation: The default limit, if a limit isn’t mentioned are, 0 for lower limit and 1 for upper. Here, we’ve only mentioned the lower limit as 3 and the upper limit gets initialized as 0. This causes a typical error since there can’t be a uniform distribution whose lower limits is greater than the upper limit.
5. What is the output of the following code?
p=input(''); po
a) ‘po’ gets assigned to p
b) Error in the input
c) Error due to syntax
d) Cannot be determined
View Answer
Explanation: The given input, po, results in an error. If after the input() command, we want to give a text input, we need to include the input within ‘’. Since we’ve not given po within ‘’, it results in an error.
6. What is the output of the following code?
p=input[''];
a) Asks for an input
b) Error in the input
c) Error due to syntax
d) Cannot be determined
View Answer
Explanation: There is a syntactical error in the above code. This is because we’ve given [] after the input command but the syntax of the input command requires us to put parentheses after it. This leads to an error.
7. What is the output of the following code?
pd=makedist('Uniform','-Inf',lower,'Inf',upper)
a) Makes a uniform distribution ranging from -Inf to Inf
b) Error due to Inf
c) Error due to syntax
d) Logical Error
View Answer
Explanation: Before mentioning the lower limit for the uniform distribution, we need to mention ‘lower’. Even though we will receive an error, due to Inf, if the aforementioned syntax is followed- that will be the 2nd error MATLAB observes while the first error is the fact that lower is mentioned after defining the lower limit. This leads to an error.
8. What is the output of the following code?
sumsqr([1 2; 'NaN' 4])
a) 21
b) Error due to NaN
c) Error due to ‘NaN’
d) 9
View Answer
Explanation: When we write NaN within ‘’, we declare it as a character. Now, the sumsqr command can only take integers as input. Since there is a character0 it results in an error. Hence, the output is option c and not b. If it was not placed within ‘’, it would’ve been ignored and the output would’ve been 21.
9. The uniform distribution can range from -infinity to 0 or 0 to Infinity but not from -infinity to infinity.
a) True
b) False
View Answer
Explanation: The uniform distribution can typically range from (-Inf,Inf), i.e. the lower and upper limits of the distribution cannot be less than or -Infinity or more than Infinity respectively. Hence, this leads to an error.
10. If a character input is given to a command which only takes integers, it’ll always give an error.
a) True
b) False
View Answer
Explanation: MATLAB is very sensitive to the nature of inputs defined for a particular command. If the input to a command has to be an integer but we give a character input, it’ll give an error.
Sanfoundry Global Education & Learning Series – MATLAB.
To practice all areas of MATLAB, here is complete set of 1000+ Multiple Choice Questions and Answers.