how can I split an array into n arrays?

21 ビュー (過去 30 日間)
sara
sara 2015 年 2 月 21 日
回答済み: Stephen23 2015 年 2 月 22 日
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 Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by