MATLAB Questions and Answers – M-Files

This set of MATLAB Multiple Choice Questions & Answers (MCQs) focuses on “M-Files”.

1. How would you start a debugger in MATLAB?
a) There is no M-file in MATLAB
b) Type edit in MATLAB and press Enter
c) Type debug in MATLAB and press Enter
d) Type M-file in MATLAB and press Enter
View Answer

Answer: b
Explanation: M-files are simple text files containing MATLAB programs. These can be used to run complex programs easily. In MATLAB, we can type edit to begin writing in Editor/Debugger mode. Typing debug or M-file won’t do any good.

2. What is the extension of script files?
a) .m
b) .mat
c) .script
d) There is a nothing called script file
View Answer

Answer: a
Explanation: Script files are a kind of M-file. So to save a script file, it has to saved with a .m extension. On the other hand, .mat extension is for MAT files.

3. What is the basic difference between M-files and MAT-files?
a) There is no difference
b) MAT files are binary data files while m-files are ASCII text files
c) M files are binary data files while MAT-files are ASCII text files
d) There is no such thing as MAT files
View Answer

Answer: b
Explanation: M-files are ASCII text files which are used to simplify our program editing in MATLAB, they are basic text files. MAT files are Binary files created by MATLAB. When we need to save any data from the workspace, it is saved in MATLAB as a MAT file.
advertisement
advertisement

4. What does the echo command do?
a) It echoes
b) It shows the comments present in Script files
c) It shows the commands and comments in MAT-files
d) It shows the commands and the comments in M-files
View Answer

Answer: d
Explanation: The echo command is a pre-defined function in MATLAB. If it is present in an m-file, the command will help to show the commands and comments present in the m-file when the m-file is called in the command window.

5. What will the following command do?

Load m1
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

a) Load the script file named ‘m1’
b) Load the function file named ‘m1’
c) Load the m-file named ‘m1’
d) There is no Load command in MATLAB
View Answer

Answer: c
Explanation: The command ‘load’ is pre-defined in MATLAB. It is used to load an M-file and run it to show get the output which is supposed to be generated from the m-file. Not the m-file can be a script file or a function file. Since the question does not mention whether the m file is a script or a function file, the possible option is Load the function file named ‘m1’.

6. What will the following command do?

Save workspace
advertisement

a) Saves the entire workspace as MAT file
b) Saves a variable named ‘workspace’ as MAT file
c) Saves the entire workspace as m file
d) Saves a variable named ‘workspace’ as m file
View Answer

Answer: b
Explanation: The save command is used to save a variable from workspace. So the above command will only save a single variable, named ‘workspace’, from the workspace itself. It won’t save the entire workspace.

7. How do you create a function file in MATLAB?
a) Begin m-file with function definition
b) Begin script file with function definition
c) There is no such thing called function file
d) An m-file is only a function file
View Answer

Answer: a
Explanation: If an m-file starts with a function definition, it becomes a function file. This file can be called to generate a desired output multiple times. As MATLAB allows the making of such files, complicated big programs can be broken down to simplify the nature of the entire MATLAB program.
advertisement

8. A student is repeatedly calling a function file but gets no output. She has checked the file repeatedly so finally she asked her teacher about it. The teacher checked everything and finds the error and gives her a scolding. What is a silly mistake?
a) She was calling the wrong function
b) She has placed a semicolon at the end of the line which computes the desired values
c) She has called a .m file
d) She was calling a script file
View Answer

Answer: b
Explanation: If we write a function file, we should not put a semicolon at the line which computes a value. This will lead to the passing of cursor to the next line after the function is implemented without showing any output. So it was good that the teacher scolded her.

9. A function is not returning values according to desired input values. What should be the correction?
a) Include clear all at the beginning of function file
b) Include close all at the beginning of function file
c) Include echo on in the function file
d) Cannot be solved
View Answer

Answer: a
Explanation: Even though the variables defined within a function are local variables, they might get affected due to the previous usage. So while execution of the same function, the user might get a different answer. Thus it is advised to include clear all to remove all previous definitions of variables. The command ‘close all’ is used to clear the previously created graphs.

10. MEX files work on JAVA.
a) True
b) False
View Answer

Answer: b
Explanation: MEX files are files written in C language. They can be integrated with MATLAB. They won’t work on JAVA.

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.