how can I split an array into n arrays?

28 visualizaciones (últimos 30 días)
sara
sara el 21 de Feb. de 2015
Respondida: Stephen23 el 22 de Feb. de 2015
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

Respuestas (2)

Greig
Greig el 21 de Feb. de 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.

Stephen23
Stephen23 el 22 de Feb. de 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:

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by