So let's say I have a vector p = [1 2 3]
. I want a command that looks like this:
[x y z] = p;
so that x = p(1), y = p(2), and z = p(3).
Is there an easy way to do this?
So let's say I have a vector p = [1 2 3]
. I want a command that looks like this:
[x y z] = p;
so that x = p(1), y = p(2), and z = p(3).
Is there an easy way to do this?
Well, turns out there's no way to one-line this, so I wrote a function.
function varargout = deal_array(arr)
s = numel(arr);
n = nargout;
if n > s
error('Insufficient number of elements in array!');
elseif n == 0
return;
end
for i = 1:n
varargout(i) = {arr(i)}; %#ok<AGROW>
end
end