I’d like to create new vectors from columns of an existing matrix. My code looks like:
Matrix=[1 2 3;4 5 6;7 8 9];
A=Matrix(:,1);
B=Matrix(:,2);
C=Matrix(:,3);
I see that this code is not really elegant especially if I have a big number of columns, that’s why I’m looking for something like:
[A B C]=Matrix;
But Matlab said the matrix can’t be assigned to multiple values. Is there another way?
use mat2cell to split your original matrix up and deal to assign the splitted data to the result variables A,B and C:
Unfortunately the intermediary variable is needed (however there is the FEX function dealcell that solves this if you like one-liners)