You are on page 1of 18

1.

What is the problem with executing commands in the Command


Window in MATLAB?
a) Commands cannot be executed at all in the Command Window.
b) Commands cannot be saved and executed again for several times.
c) Commands cannot be corrected or changed once executed.
d) Commands cannot be executed repeatedly.

Answer: b) Commands cannot be saved and executed again for several


times.

2. What is the recommended way of executing commands repeatedly


with MATLAB?
a) Creating a function with a list of commands.
b) Creating a script file with a list of commands.
c) Saving the commands in a text file.
d) Entering the commands in the Command Window repeatedly.

Answer: b) Creating a script file with a list of commands.

3. What are the files used for executing a list of commands repeatedly in
MATLAB called?
a) Script files
b) Function files
c) Text files
d) Command files
Answer: a) Script files

4. What is the file extension for script files in MATLAB?


a) .mat
b) .txt
c) .m
d) .scr

Answer: c) .m

5. Can script files in MATLAB accept arguments and produce outputs?


a) No, script files can only execute a series of MATLAB statements.
b) Yes, script files can accept arguments but cannot produce outputs.
c) Yes, script files can produce one or more outputs.
d) Yes, script files can accept arguments and produce outputs.

Answer: a) No, script files can only execute a series of MATLAB


statements.

6. What is the purpose of the who command ?


a) To list all the available files in the workspace.
b) To list all the variables in the workspace.
c) To list the contents of the file.
d) To list the output of the MATLAB statements.
Answer: b) To list all the variables in the workspace.

7. What is the recommended tool for writing and editing M-files in


MATLAB?
a) A general-purpose text editor.
b) The Command Window.
c) The MATLAB debugger.
d) The MATLAB editor.

Answer: d) The MATLAB editor.

8. What are the side-effects of using script files in MATLAB?


a) Changes to the MATLAB editor preferences.
b) Overwriting variables already existing in the workspace.
c) Changes to the MATLAB installation directory.
d) Overwriting files in the current working directory.

Answer: b) Overwriting variables already existing in the workspace.

9. How can the state variables in the workspace affect the execution of a
script file?
a) They can speed up the execution of the script file.
b) They can slow down the execution of the script file.
c) They can cause unexpected behavior in the execution of the script file.
d) They have no effect on the execution of the script file.

Answer: c) They can cause unexpected behavior in the execution of the


script file.

10. What is the recommended alternative to using script files for


complicated applications in MATLAB?
a) Using a general-purpose text editor.
b) Using the Command Window.
c) Using the MATLAB debugger.
d) Using function M-files.

Answer: d) Using function M-files.

11. What are M-File functions in MATLAB?


a) Programs that cannot accept input arguments or return output
arguments.
b) Programs that accept input arguments and return output arguments.
c) Programs that can only accept input arguments but cannot return
output arguments.
d) Programs that can only return output arguments but cannot accept
input arguments.

Answer: b) Programs that accept input arguments and return output


arguments.
12. How is the workspace of an M-File function different from the base
workspace in MATLAB?
a) The workspace of an M-File function is the same as the base
workspace.
b) The workspace of an M-File function is a subset of the base
workspace.
c) The workspace of an M-File function is completely separate from the
base workspace.
d) The workspace of an M-File function overlaps with the base
workspace.

Answer: c) The workspace of an M-File function is completely separate


from the base workspace.

13. What is the advantage of using M-File functions over script files in
MATLAB?
a) M-File functions are easier to write and debug.
b) M-File functions do not have any side-effects on the base workspace.
c) M-File functions can be executed more quickly than script files.
d) M-File functions can be used to overwrite variables in the base
workspace.

Answer: b) M-File functions do not have any side-effects on the base


workspace.

14. What is the purpose of the function definition line in an M-File


function?
a) To provide a one line summary description of the program.
b) To define the function name and the inputs and outputs.
c) To provide a more detailed description of the program.
d) To contain the program code that performs the computations.

Answer: b) To define the function name and the inputs and outputs.

15. What is the purpose of the H1 line in an M-File function?


a) To define the function name and the inputs and outputs.
b) To provide a one line summary description of the program.
c) To provide a more detailed description of the program.
d) To contain the program code that performs the computations.

Answer: b) To provide a one line summary description of the program.

16. What is the purpose of the help text in an M-File function?


a) To define the function name and the inputs and outputs.
b) To provide a one line summary description of the program.
c) To provide a more detailed description of the program.
d) To contain the program code that performs the computations.

Answer: c) To provide a more detailed description of the program.

17. Which part of an M-File function contains the program code that
performs the actual computations?
a) Function definition line
b) H1 line
c) Help text
d) Function body

Answer: d) Function body

18. Can scripts have all the elements shown in Table 4.1?
a) Yes, scripts can have all the elements except for the function
definition line.
b) No, scripts do not have any of the elements shown in Table 4.1.
c) Yes, scripts can have all the elements including the function definition
line.
d) Scripts can only have the function body element.

Answer: a) Yes, scripts can have all the elements except for the function
definition line.

19. What are the naming rules for a function in MATLAB?


a) Function name must begin with a number.
b) Function name must begin with a special character.
c) Function name must begin with a letter.
d) Function name must be longer than 63 characters.

Answer: c) Function name must begin with a letter.


20. What is the maximum length of a function name in MATLAB?
a) 16 characters
b) 32 characters
c) 63 characters
d) 128 characters

Answer: c) 63 characters

21. What is the file extension for a function file in MATLAB?


a) .mat
b) .txt
c) .scr
d) .m

Answer: d) .m

22. What is the main difference between scripts and functions in


MATLAB?
a) Scripts can accept input arguments and return output arguments, while
functions cannot.
b) Functions can accept input arguments and return output arguments,
while scripts cannot.
c) Scripts store variables in a workspace that is shared with other scripts,
while functions store variables in an internal workspace.
d) Functions are useful for automating a series of commands, while
scripts are useful for extending the MATLAB language for your
application.

Answer: b) Functions can accept input arguments and return output


arguments, while scripts cannot.

23. How are input arguments listed in a function definition line in


MATLAB?
a) Inside brackets on the left side of the function name.
b) Inside parentheses on the left side of the function name.
c) Inside brackets on the right side of the function name.
d) Inside parentheses on the right side of the function name.

Answer: b) Inside parentheses on the left side of the function name.

24. How are output arguments listed in a function definition line in


MATLAB?
a) Inside brackets on the left side of the function name.
b) Inside parentheses on the left side of the function name.
c) Inside brackets on the right side of the function name.
d) Inside parentheses on the right side of the function name.

Answer: a) Inside brackets on the left side of the function name.


25. What is the purpose of output arguments in a function definition line
in MATLAB?
a) To list the inputs required for the function.
b) To transfer the output from the function file.
c) To define the name of the function.
d) To define the type of the function.

Answer: b) To transfer the output from the function file.

26. Can a function file have several output arguments?


a) Yes, a function file can have several output arguments.
b) No, a function file can have only one output argument.
c) A function file cannot have any output arguments.
d) The number of output arguments in a function file is limited to three.

Answer: a) Yes, a function file can have several output arguments.

27. What are the three ways to assign values to variables in a script file
in MATLAB?
a) The variable is defined in the script file, it is defined in the command
prompt, or it is entered when the script is executed.
b) The variable is assigned a value automatically, it is assigned a value
by the user, or it is assigned a value by the system.
c) The variable is defined in the script file, it is defined in the function
file, or it is defined in the command window.
d) The variable is assigned a value by the user, it is assigned a value by
the system, or it is assigned a value randomly.

Answer: a) The variable is defined in the script file, it is defined in the


command prompt, or it is entered when the script is executed.

28. What is the input command used for in MATLAB?


a) To define a variable in a script file.
b) To assign a value to a variable in a script file.
c) To execute a script file.
d) To define a function.

Answer: b) To assign a value to a variable in a script file.

29. In which case is the user prompted to assign a value to a variable in


the command prompt when executing a script file in MATLAB?
a) The variable is defined in the script file.
b) The variable is defined in the command prompt.
c) The variable is defined in the function file.
d) The variable is assigned a value automatically.

Answer: a) The variable is defined in the script file.

30. Can a variable be assigned a value using the input command in a


function file in MATLAB?
a) Yes, a variable can be assigned a value using the input command in a
function file.
b) No, a variable can only be assigned a value in a script file.
c) A variable cannot be assigned a value using the input command in
either a script file or a function file.
d) A variable can only be assigned a value using the input command in
the command prompt.

Answer: b) No, a variable can only be assigned a value in a script file.

31. What are the two commands frequently used to generate output in
MATLAB?
a) input and output
b) disp and fprintf
c) define and output
d) display and print

Answer: b) disp and fprintf

32. What is the main difference between the disp and fprintf commands
in MATLAB?
a) disp provides total control over the appearance of output, while fprintf
provides limited control over the appearance of output.
b) fprintf is simpler to use than disp.
c) disp provides limited control over the appearance of output, while
fprintf provides total control over the appearance of output.
d) fprintf is used to generate automatic displays, while disp is used to
generate user-defined displays.

Answer: c) disp provides limited control over the appearance of output,


while fprintf provides total control over the appearance of output.

33. Which command is simpler to use, disp or fprintf?


a) disp is simpler to use than fprintf.
b) fprintf is simpler to use than disp.
c) Both commands are equally simple to use.
d) Neither command is easy to use.

Answer: a) disp is simpler to use than fprintf.

34. Which command provides total control over the appearance of


output in MATLAB, disp or fprintf?
a) disp provides total control over the appearance of output.
b) fprintf provides total control over the appearance of output.
c) Both commands provide total control over the appearance of output.
d) Neither command provides total control over the appearance of
output.

Answer: b) fprintf provides total control over the appearance of output.

35. What are the decision making structures for control of command
execution in MATLAB?
a) Functions and scripts
b) Variables and assignments
c) Control flow structures
d) Input and output commands

Answer: c) Control flow structures

36. What are the three control flow structures that MATLAB include ?
a) if-else-end, for loop, and while loop
b) if-then-else, do-while, and switch-case
c) if-then-else, for loop, and switch-case
d) if-else-end, do-while, and switch-case

Answer: a) if-else-end, for loop, and while loop

37. What is the purpose of control flow structures in MATLAB?


a) To compile the program
b) To interpret the program
c) To control the execution of commands in a program
d) To add new functions to MATLAB

Answer: c) To control the execution of commands in a program

38. Does MATLAB need to compile programs before they can be run?
a) Yes, MATLAB needs to compile programs before they can be run.
b) No, MATLAB is an interpretative language and does not require
programs to be compiled.
c) Only script files need to be compiled, function files do not.
d) It depends on the size of the program.

Answer: b) No, MATLAB is an interpretative language and does not


require programs to be compiled.

39. Can users add their own functions to MATLAB using M-files?
a) Yes, users can add their own functions to MATLAB using M-files.
b) No, MATLAB does not allow users to add their own functions.
c) Users can only add functions to MATLAB using compiled code.
d) Users can only add functions to MATLAB using script files.

Answer: a) Yes, users can add their own functions to MATLAB using
M-files.

40. How can a while loop be terminated in MATLAB?


a) With the continue statement
b) With the switch statement
c) With the break statement
d) With the return statement

Answer: c) With the break statement


41. What is the purpose of the continue statement in MATLAB?
a) To exit a loop
b) To terminate a loop
c) To skip to the next iteration of a loop
d) To return a value from a function

Answer: c) To skip to the next iteration of a loop

42. What other control statements are available in MATLAB, besides


break and continue?
a) Return, continue, switch
b) Start, stop, pause
c) If, else, endif
d) While, for, do

Answer: a) Return, continue, switch

43. How can output be saved to a file in MATLAB?


a) Using the fprintf command
b) Using the open command
c) Using the close command
d) Using the save command
Answer: a) Using the fprintf command

44. What are the steps required to save output to a file in MATLAB?
a) Open a file using fopen, write the output using fprintf, close the file
using fclose
b) Open a file using fprintf, write the output using fopen, close the file
using fclose
c) Open a file using fclose, write the output using fprintf, close the file
using fopen
d) Open a file using fwrite, write the output using fprintf, close the file
using fclose

Answer: a) Open a file using fopen, write the output using fprintf, close
the file using fclose

45. What format is required to save output to a file in MATLAB?


a) Binary format
b) Text format
c) Image format
d) Audio format

Answer: b) Text format

46. What is the purpose of the fopen command in MATLAB?


a) To write output to a file
b) To close a file
c) To open a file for reading or writing
d) To format output for display on the screen

Answer: c) To open a file for reading or writing

47. What is the purpose of the fclose command in MATLAB?


a) To write output to a file
b) To close a file
c) To open a file for reading or writing
d) To format output for display on the screen

Answer: b) To close a file

You might also like