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
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?
d) There is a nothing called script file
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
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.
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
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?
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
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?
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
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
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.
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
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
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.
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.