How to organize large column in to small Commons.

1 view (last 30 days)
friet
friet on 17 Sep 2018
Answered: Adam Danz on 17 Sep 2018
Hello I have a large col vector in matlab with size of ~10000. I would like to cut the col at every 100 point as you see it below separate each col. and save it in separate
a1=[x(1:100)];
a2=[x(101:200)];
a3=[x(201:300)];
a4=[x(301:400)];... and so on.
Z=[a1,a2,a3]
However doing like this will take forever. Is ther anyway to do it in loop. Any help is appreciated.
best,

Answers (1)

Adam Danz
Adam Danz on 17 Sep 2018
This requires dynamic variable naming and it's not a good practice. To understand why read this:
Instead, if the length of your vector is a multiple of 100 and your data are numeric, turn your vector into a matrix where each column is your 'a1', 'a2', etc. Here's an example using reshape().
data = rand(10000,1);
dataMat = reshape(data, 100, []);
Your variable a12 is just column 12
dataMat(:,12)
If your data are not all numeric or the length of your vector is not a multiple of 100, describe your dataset and we can work out a solution using cell arrays.

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!