Effacer les filtres
Effacer les filtres

Reshaping / regrouping cell arrays?

5 vues (au cours des 30 derniers jours)
Cameron Spooner
Cameron Spooner le 16 Août 2016
Modifié(e) : Azzi Abdelmalek le 16 Août 2016
I have 3 cell arrays. I would like to reshape these arrays so that each column is grouped into cells of a defined size. The amount of columns per array varies.
E.g. Start with matrix below;
[1] [2] [3]
[4] [5] [6]
[7] [8] [9]
[10] [11] [12]
I'm trying to group each column by the same value, say 2. Then each cell would have the dimensions 1X2. Then it would be formatted like;
[1;4] [2;5] [3;6]
[7;10] [8;11] [9;12]
And if the value was a number that didn't divide by the total rows, like 3, then it would be formatted with the remainder untouched;
[1;4;7] [2;5;8] [3;6;9]
[10] [11] [12]
How would I do that? I've tried reading the helpfiles and couldn't find any examples that looked similar.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 16 Août 2016
Modifié(e) : Azzi Abdelmalek le 16 Août 2016
Edit
A=num2cell(reshape(1:12,3,4)') %-----Example---
[n,m]=size(A)
k=3
p=fix(n/k)
AA=A(1:p*k,:)
B=mat2cell(cell2mat(AA),k*ones(1,p),ones(1,m))
nn=n-p*k
B=[B;A(k*p+1:k*p+nn,:)]

Plus de réponses (0)

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by