Default argument expression with multiple outputs
3 views (last 30 days)
How do I get the correct output into the default argument if a function used in an expression has more than one output? E.g.
opts.input2 (1,1) double = function_with_multiple_outputs(function_inputs)
Where [output1, output2, etc] = function_with_multiple_outputs(function_inputs) and function_inputs are constants or previously defined arguments. I only want, e.g. opts.input2 to be output2 from function_with_multiple_outputs.
Steven Lord on 22 Aug 2023
Write a local function that calls function_with_multiple_outputs with multiple outputs then returns only the one you want to use for the default value. Call that local function instead of function_with_multiple_outputs in the arguments block.
More Answers (2)
dpb on 22 Aug 2023
Multiple output arguments must be unique variable names; just define the default for the specific name and it will refer to the one in that position.
Walter Roberson on 22 Aug 2023
In MATLAB, there is no (useful) way to assign multiple outputs of a function to a single location, and there is no (useful) way to select a particular output from a command .
What would be legal generally in MATLAB (but not necessarily in an argument block) is
[opts.input2, opts.input2] = function_with_two_outputs();
This would assign the first output to opts.input2 and then assign the second output on top of opts.input2 .