Recall & Review
beginner
What is the basic syntax to define a function in MATLAB?
Use the
function keyword followed by the output variable(s), the function name, and input variable(s). Example:<br>function output = functionName(input)
Click to reveal answer
beginner
How do you define a function with multiple outputs in MATLAB?
List the output variables inside square brackets separated by commas. Example:<br>
function [out1, out2] = myFunction(in1, in2)
Click to reveal answer
intermediate
Where must the function definition be placed in a MATLAB file?
The function definition must be the first executable line in the file if it is a function file. If the file contains multiple functions, the first function is the main function, and others are local functions below it.
Click to reveal answer
beginner
Can MATLAB functions have no input or no output arguments? How?
Yes. For no inputs, just omit input variables:<br><pre>function output = myFunction()</pre><br>For no outputs, omit output variables:<br><pre>function myFunction(input)</pre>Click to reveal answer
intermediate
What happens if you do not specify output variables in a MATLAB function?
The function will not return any output to the caller. It can still perform actions like displaying results or modifying files, but no data is returned.
Click to reveal answer
Which keyword starts a function definition in MATLAB?
✗ Incorrect
MATLAB uses the keyword
function to define functions.How do you define a function with two outputs named
a and b?✗ Incorrect
Multiple outputs are enclosed in square brackets separated by commas.
Where should the main function be placed in a MATLAB file?
✗ Incorrect
The main function must be the first executable line in the file.
What is the correct way to define a function with no inputs but one output?
✗ Incorrect
Use empty parentheses to indicate no inputs.
If a MATLAB function does not specify output variables, what happens?
✗ Incorrect
Without output variables, the function returns nothing to the caller.
Explain the syntax to define a MATLAB function with multiple outputs and inputs.
Think about how you list outputs and inputs in the function line.
You got /4 concepts.
Describe where and how you place function definitions inside a MATLAB file.
Consider the order of functions in the file.
You got /3 concepts.