how can I split an array into n arrays?

26 次查看(过去 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

回答(2 个)

Greig
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.

Stephen23
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:

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by