Suppose I have some function foo (not written by me) that returns multiple values, like this:
function [one, two, three, four] = foo()
one = 2;
two = 4;
three = 8;
four = 16;
end
(NB: the above is just an example; in general, I have no control over the function foo.)
Furthermore, suppose that I'm in the middle of a MATLAB debugging session.
If I now evaluate foo, only the first of the values it returns gets displayed:
K>> foo()
ans =
2
If I try to capture all the values with an assignment expression, I get one error or another; for example:
K>> all_returned_values = foo()
Attempt to add "all_returned_values" to a static workspace.
See Variables in Nested and Anonymous Functions.
K>> [v1 v2 v3 v4] = foo()
Attempt to add "v1" to a static workspace.
See Variables in Nested and Anonymous Functions.
K>> {v1 v2 v3 v4} = foo()
{v1 v2 v3 v4} = foo()
↑
Error: The expression to the left of the equals sign is not a valid target for an assignment.
Is there a way to force MATLAB to return all the values of the function that does not rely on an assignment?
NB: I'm looking for a solution that does not require modifying the function foo in any way. (This function may not be under my control; e.g., it could be a built-in MATLAB function.)