Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB Easiest way to assign elements of a vector to individual variables [duplicate]

Tags:

matlab

Possible Duplicate:
How do I do multiple assignment in MATLAB?

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?

like image 408
rlbond Avatar asked May 23 '10 20:05

rlbond


1 Answers

Convert to cell array.

pCell = num2cell(p);
[x,y,z] = pCell{:};
like image 54
Jonas Avatar answered Oct 30 '22 14:10

Jonas