I have a function that returns multiple values:
function [a,b,c] = f()
a = 1; b = 2; c = 3;
end
How to I save the output into a vector without having to create intermediate variables? Example shown below:
> z = zeros(1,3);
> [a,b,c] = f();
> z(:) = [a,b,c];
> z
ans =
1 2 3
I don't have to define intermediate variables a
, b
, c
, but only if I define an additional cell array:
> ce = cell(1, 3);
> [ce{:}] = f();
> z(:) = cell2mat(ce);
> z
ans =
1 2 3
Is there a better way to go directly from z(:) = f()
?