MATLAB Questions and Answers Part-2

1. Command is used to save command window text to file.
a) saveas
b) texttofile
c) diary
d) todiary

Answer: c
Explanation: The diary function creates a log of keyboard input and the resulting text output, with some exceptions. The output of diary is an ASCII file, suitable for searching in, printing, inclusion in most reports and other documents.

2. Which command is used to clear a command window?
a) clear
b) clc
c) close all
d) clear all

Answer: b
Explanation: clc clears all input and output from the Command Window display and provide a “clean screen”. After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow key, ↑, to recall statements from the command history.

3. Which functions help you to save and load variables?
a) >> save Lays [a,b]
>> load('myfile.mat')
b) >> save Lays {a b}
>> load myfile.mat
c) >> save Lays “a,b”
>> load(myfile.mat)
d) >> save Lays a b
>> load('myfile.mat')

Answer: d
Explanation: There is a pre-defined function in MATLAB to store the variable values from your workspace permanently called ‘save filename’. Option d is the correct command syntax for calling it.

4. What will the following set of commands do when they are present in a script file?
stem[y1,y2];
title(‘p’);
print -deps p
a) Plot the discrete graph of y1 and y2
b) There is no stem command in MATLAB
c) Store the graph as a separate file
d) Cannot be determined

Answer: c
Explanation: The given format of the print statement is used to store the graphs of y1 and y2 generated due to previous definitions of y1 and y2. If we only use the print command, the graph y1 and y2 will get displayed.

5. How to stop the execution of a chain of commands?
a) Press Ctrl +c
b) Cannot be stopped
c) Only usage of debugging mode is possible in MATLAB
d) Quit

Answer: a
Explanation: It may so happen that we want to pause the execution of a set of commands at a certain point. We only need to press Ctrl and C together to pause it. On the other hand, quit causes the MATLAB software to shut down. Debugging modes are also available in MATLAB.

6. To display comments of M-file, we use ____________
a) show %
b) echo on
c) comment on
d) Cannot be displayed

Answer: b
Explanation: The echo command is used to display commands present in an M-file. If the M-file has any comments, the echo command will also display the comments.

7. What are MEX files in MATLAB?
a) No such thing as MEX files
b) Same as MAT files
c) Helps to analyse commands in MATLAB
d) Allows the user to combine C source files with Matlab files

Answer: d
Explanation: MEX files are one of the kinds of file modes available in MATLAB. They are saved with a .mex extension. These files help in the association of C source files into the programs written in MATLAB.

8. The function to close the windows containing graphs generated from MATLAB is __________
a) close all
b) close graphs
c) delete graphs
d) end all

Answer: a
Explanation: The command close all is a pre-defined function in MATLAB. When it is called, MATLAB will automatically shut down the separate windows that have been opened to view graphs separately. The rest of the options are wrong.

9. What are the difference between the ‘help’ and the ‘look for’ command?
a) No difference
b) Syntactical difference
c) Help returns the entire set while look for returns specific commands
d) Help returns all the toolbox while look for returns a single toolbox

Answer: c
Explanation: The ‘help’ command is used to return all the commands surrounding a particular toolbox name entered along with it. The ‘look for’ command is used to return a particular function or set of functions whose name matches with the keyword entered in along with the ‘look for’ command.

10. What is not displayed by the Workspace?
a) Time of variable generation
b) Standard deviation of the variable values
c) Class of the variables
d) Nature of the variables

Answer: a
Explanation: By right clicking on the Workspace header, we will get to know the characteristics of the variables which are stored in the Workspace and what it can display. The time of variable generation is not present in the Workspace. It can only be seen if the variables from the workspace are saved separately using the command ‘save filename’.