MATLAB Questions and Answers – Errors in Input – 2

«
»

This set of MATLAB Questions and Answers for Freshers focuses on “Errors in Input – 2”.

1. What is the output of the following code?

advertisement
isvector((49 32));

a) Error in ()
b) Error due to absence of comma
c) Error due to command
d) Logical 1
View Answer

Answer: a
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.
advertisement
advertisement

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

Answer: a
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.
advertisement

3. What is the output of the following code?

advertisement
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

Answer: a
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.
advertisement

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

Answer: a
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

Answer: b
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

Answer: c
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

Answer: c
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

Answer: c
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

Answer: b
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

Answer: a
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 for Freshers, here is complete set of 1000+ Multiple Choice Questions and Answers.

Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter