MATLAB Questions and Answers – Spelling Error – 1

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

1. What is the output of the following code?

T=-9:0:9;
STEM(T);

a) Error
b) Plots a ramp function from 0 to 9 units in time
c) Plots a discrete function
d) Logical Error
View Answer

Answer: a
Explanation: MATLAB is sensitive to uppercase and lowercase letters. The stem command has been written in uppercase letters so it is not recognized by MATLAB. It should be written in lowercase letters and then the output would be Plots a discrete function.
advertisement
advertisement

2. What is the output of the following code?

N=Input[‘’];

a) Ask for an input from the user
b) Asks for an input from the user which has to be kind of number
c) Input command does not exist
d) Syntactical Error
View Answer

Answer: c
Explanation: There is a syntactical error since the input to the input command should be within parentheses. But the first error MATLAB notices is that it doesn’t recognize the command due to the Uppercase I. This leads to an error.
Note: Join free Sanfoundry classes at Telegram or Youtube

3. Given below is a part of a very big program. What is the output?

advertisement
A=[1 2 3];
mean(a);

a) Error
b) 2
c) Cannot be determined
d) The mean of a
View Answer

Answer: c
Explanation: Since the variable a is not defined, the input to the mean command does not exist. This is a very common mistake and it should be checked upon. The variable is ‘A’ and if the input was mean(A), the output would’ve been 2. But here there is an error.
advertisement

4. A student is trying to plot multiple plots in the same window. But the following code doesn’t allow him to do that. What is the error?

t=0:1:9;
stem(t);
hld;
stem(t^2);

a) Error in t^2
b) Error in hld
c) No error
d) Error in stem(t)
View Answer

Answer: b
Explanation: There will be an error in t^2 since t is a vector. But the first error MATLAB observes is the hld, it is supposed to be hold. The hold command results in holding the window of the current plot of stem(t) so that multiple commands can be plotted in it. But since it has been misspelled.

5. What is the output of the following code?

Recpulse(1,9)

a) A column vector of 1’s of length 9
b) A column vector of 1’s of length 10
c) A row vector of 1’s of length 9
d) Error
View Answer

Answer: d
Explanation: The command is spelled wrong, it should’ve been rectpulse, with the R in lowercase. If the command was rectpulse(1,9), the output would’ve been a column vector of 1’s of length 9.

6. What is the output of the following code?

tripulse(3)

a) Error
b) 0
c) 1
d) 2
View Answer

Answer: a
Explanation: There is an error in the following code. The tripulse command is misspelled, it should be tripuls(3). The output would’ve been 0 if there was no spelling error.

7. What is the output of the following code?

Mean([1 2 3 4])

a) Error due to the Mean command
b) 2.5
c) 2 and 3
d) Syntactical Error
View Answer

Answer: a
Explanation: The actual command is ‘mean’ which would yield 2.5 as output. But the uppercase M, int the given command, results in an error since MATLAB doesn’t recognize it. Since there is no syntactical error- even if there was, MATLAB would’ve first returned the first error.

8. What is the output of the following code?

lengths([1 2 3])

a) 3
b) 1*3
c) Error due to lengths command
d) Cannot be determined
View Answer

Answer: c
Explanation: The length command is used but since we have an extra ‘s’ after it, the command is not recognized by MATLAB. Hence, this leads to an error. Otherwise, the output would’ve been 3 only.

9. What is the output of the following code?

sten([0:1:4],2*ones(1,5)]

a) A discrete step function
b) A discrete pulse function from 0 to 4 units in time
c) A ramp function
d) Error
View Answer

Answer: d
Explanation: The stem command is misspelled as sten which leads to an error. The output would’ve been a discrete pulse function from 0 to 4 units in time but due to this, there is an error as an output.

10. There are a few commands, in MATLAB, which can be used by ignoring the cases.
a) True
b) False
View Answer

Answer: b
Explanation: All the commands, predefined in MATLAB, are in lowercase and they cannot be called by uppercase letters. Hence, the above statement is false.

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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). 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!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.