MATLAB Questions and Answers – Suppressing Output

«
»

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “Suppressing Output”.

1. Graphs are not suppressed by the ‘;’.
a) True
b) False
View Answer

Answer: b
Explanation: The commands to generate any kind of graph will always result in an opening of a new window when they are used as required. The ‘;‘ won’t suppress it.
advertisement

2. What will be the output of the following code?

close all;
for x = 1.5 : .5 : 2;
y=3; 
x=y+3
 clc
end

a) No value will be stored
b) The result will be printed
c) The result will be printed twice but no value will remain in the Workspace
d) The loop will not run
View Answer

Answer: c
Explanation: The loop will run twice and the final value of y is 5 while that of x is 2. Each time the loop runs, no result shall be printed since the ‘ ; ‘ at the end of the last line suppresses the result and it gets stored in MATLAB.

Output:  x = 4.5
         x = 5
advertisement
advertisement

3. What will be the output of the following code?

advertisement
for i = 1 :4: 5
y=i+1
clear i
end

a) y=5; i=2
b) y=5, printed twice
c) Loop will run once, y=2
d) Infinite loop
View Answer

Answer: b
Explanation: The index of a loop is a separate variable. It will get added to y in the first iteration and y will have value 2. Now even though we have the index i=1 in the workspace, it will get cleared from it but the loop will continue with i=1. So the final value of y will be y=5+1=6. The loop won’t be an infinite loop.

Output:  y = 2
         y = 6
advertisement

4. Clear will removes all graphs.
a) True
b) False
View Answer

Answer: b
Explanation: Clear all removes variables from the workspace. It does not remove graphs.

5. What will be the output of the following code?

advertisement
for i=1 : 3
i=i-1
end

a) i will be printed thrice as 0,1,2 successively
b) Infinite loop
c) No output
d) i=2
View Answer

Answer: a
Explanation: The index of a loop is a separate variable. The value of I at the first iteration is 1 so at the end of the first iteration, it will print 0. This does not mean that the index variable will also be 0. Thus So i will be printed thrice as 0,1,2 successively.

Output:	i = 0
        i = 1
        i = 2

6. How can we close all graphs in MATLAB?
a) Using the close command
b) Using the clear all command
c) Using the close all command
d) Using the clear command
View Answer

Answer: b
Explanation: The in-built command to close the windows containing graphs is ‘close all’. This command should be placed at the beginning of a function which creates graphs so that future commands do not affect the graph generated every time the function is called.

7. clc in a function will clear the function.
a) True
b) False
View Answer

Answer: b
Explanation: Suppose we have the clc command at the end of an M-file. The purpose of clc command is to clear the command window. So when we call the function, it will clear the command window but the function will not be cleared.

8. What will be the output of the following code?

for i = 1 : 1
p=i-1
i=i+1;
clc
end

a) i=2
b) p will be printed
c) Error
d) Cannot be determined
View Answer

Answer: a
Explanation: The value of i won’t be printed since we have ended it with a semi-colon. The value of p will get printed and then the clc command will remove it from the command window. Instead, the value of I will be stored in the workspace as 2.

9. ___________ will give a hint that the file is closed.
a) Fopen
b) Fclose
c) Gclose
d) clc
View Answer

Answer: b
Explanation: The Fclose command will close the file and returns an integer value to the monitor screen to signify the operation of the command. If it returns 1, the file is closed.

10. To delete one variable but not the entire workspace, we need to mention the variable name after the clear command.
a) True
b) False
View Answer

Answer: a
Explanation: The clear command removes every variable from the workspace. If we only mention the variable name, it will delete only that variable from the workspace and not the entire workspace will be cleared.

Sanfoundry Global Education & Learning Series – MATLAB.

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