how can I split an array into n arrays?
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Greig
2015-2-21
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 个评论
Stephen23
2015-2-22
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!