How to create sequences of vector from a matrix's columns?
Show older comments
Lets say we have a matrix:
data= [240 7 0.0070 100
200 10 0.0095 50
220 8.5 0.0090 80 ];
To, create vectors from each columns we usually write
P1 = data(:,1);
P2 = data(:,2);
P3 = data(:,3);
P4 = data(:,4);
Is it possible initialize P1, P2, P3, and P4 with a loop? I have hundred columns of matrix needed to be vectorized. Thanks everyone.
Accepted Answer
More Answers (1)
KSSV
on 30 Oct 2016
2 votes
Why you want to name them p1,p2,p3 etc when already yu can access them by data(:,1),data(:,2)etc. Naming variable the way you want is called dynamic variable naming. This is not suggested.
More on
1 Comment
Ridho Ibrahim
on 30 Oct 2016
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!