Recall & Review
beginner
What does 'multiple outputs' mean in MATLAB functions?
It means a function can return more than one result at the same time, separated by commas.
Click to reveal answer
beginner
How do you define a MATLAB function that returns two outputs?
Use square brackets around output names in the function definition, like: <br>
function [out1, out2] = myFunc(input)Click to reveal answer
beginner
How do you call a MATLAB function that returns multiple outputs?
Assign outputs to variables using square brackets, like: <br>
[a, b] = myFunc(x)Click to reveal answer
intermediate
What happens if you call a MATLAB function with multiple outputs but only ask for one?
MATLAB returns only the first output and ignores the others.
Click to reveal answer
beginner
Show a simple MATLAB function that returns the sum and product of two numbers.
function [sumVal, prodVal] = sumAndProduct(a, b)
sumVal = a + b;
prodVal = a * b;
end
Click to reveal answer
How do you define multiple outputs in a MATLAB function?
✗ Incorrect
In MATLAB, multiple outputs are defined by enclosing output variable names in square brackets in the function definition.
What will MATLAB return if you call a function with multiple outputs but only assign one variable?
✗ Incorrect
MATLAB returns only the first output if you assign only one variable when calling a function with multiple outputs.
How do you capture two outputs from a MATLAB function named 'calc'?
✗ Incorrect
Use square brackets to capture multiple outputs: [x, y] = calc()
Which of these is a valid MATLAB function header for multiple outputs?
✗ Incorrect
Only option D uses correct MATLAB syntax with square brackets for multiple outputs.
If a function returns three outputs but you only want the second, how can you get it?
✗ Incorrect
Use the tilde (~) to ignore unwanted outputs and capture the second output.
Explain how to create and use a MATLAB function that returns multiple outputs.
Think about how you write the function header and how you get the results when calling it.
You got /4 concepts.
Describe what happens if you call a MATLAB function with multiple outputs but only assign one variable to receive the result.
Consider MATLAB's default behavior when fewer outputs are requested.
You got /3 concepts.