0
0
MATLABdata~5 mins

Multiple outputs in MATLAB - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AUse square brackets around output variables in the function header
BSeparate outputs with semicolons
CUse curly braces around outputs
DList outputs separated by spaces
What will MATLAB return if you call a function with multiple outputs but only assign one variable?
AAn error
BAll outputs as a list
CThe last output
DOnly the first output
How do you capture two outputs from a MATLAB function named 'calc'?
Ax, y = calc()
B[x, y] = calc()
Cx = calc()
D{x, y} = calc()
Which of these is a valid MATLAB function header for multiple outputs?
Afunction [out1, out2] = myFunc(input)
Bfunction out1, out2 = myFunc(input)
Cfunction {out1, out2} = myFunc(input)
Dfunction (out1, out2) = myFunc(input)
If a function returns three outputs but you only want the second, how can you get it?
Asecond = func(2)
B[second] = func()
C[~, second, ~] = func()
Dfunc(second)
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.