Filter löschen
Filter löschen

Reshaping / regrouping cell arrays?

5 Ansichten (letzte 30 Tage)
Cameron Spooner
Cameron Spooner am 16 Aug. 2016
Bearbeitet: Azzi Abdelmalek am 16 Aug. 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.

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 16 Aug. 2016
Bearbeitet: Azzi Abdelmalek am 16 Aug. 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,:)]

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by