how can I split an array into n arrays?
29 views (last 30 days)
Show older comments
hi everyone how can I split an array into n arrays? for exp I have a 380133*2 array how can I split this to 13 arrays with 29241*2 size?? Is there any command for this...thanks
0 Comments
Answers (2)
Greig
on 21 Feb 2015
One possible option is to use mat2cell...
C = mat2cell(X, size(X,1)/13.*ones(13,1), 2);
Each cell of C now contains a 29241x2 double. C{1} returns the first array, C{2} the second, etc.
0 Comments
Stephen23
on 22 Feb 2015
In MATLAB it is much faster to keep your data together, and learn to use indices to access the parts that you want to work with. Or you could split the data into a cell array (as Greig suggested) or a structure array.
Dynamically creating new variables is not recommended in MATLAB, and if you do this you will find it a battle to get lots of basic things done. MATLAB works best when you keep your data together, and learn to perform your operations on whole arrays, including operation vectorization and array preallocation.
In case you are interested, here are some pages explaining why dynamically assigning variable names is a really bad idea in MATLAB:
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!