# splitting large cell array into smaller cell arrays

3 visualizzazioni (ultimi 30 giorni)
Commentato: Aditya il 27 Apr 2015
hi
I have a large cell array "a" (5290*1) such that each element of the array is of size e.g. size(a{1,1}) = 21*204
i want to split these further such that each element of a{1,1} contains another cell array such that size of a{1,1}.b1 = 3*204 and i have a{1,1}.b1, a{1,1}.b2.... a{1,1}.b7 so a{1,1} contains 7 cells of size 3*204. how can i achieve this without for loop?
Many thanks for you help.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Michael Haderlein il 27 Apr 2015
If you really want to have the inside to be a struct, you can go with
c=cellfun(@(x) cell2struct(mat2cell(x,3*ones(7,1),204),{'b1','b2','b3','b4','b5','b6','b7'}),a,'uniform',false);
For sure, the {'b1'...'b7'} can be done nicer (ask if you need help with that).
Anyway, most likely it's better to keep the internal to be cells, then the upper code simplifies to
c=cellfun(@(x) mat2cell(x,3*ones(7,1),204),a,'uniform',false);
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
thanks!

Accedi per commentare.

### Più risposte (1)

Guillaume il 27 Apr 2015
Use mat2cell to split your matrices into cells. This assumes that all matrices are the same size:
newa = cellfun(@(m) mat2cell(m, 3*one(1, 7), 204), a, 'UniformOutput', false)
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
thanks!

Accedi per commentare.

### Categorie

Scopri di più su Structures in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by