フィルターのクリア

Reshaping / regrouping cell arrays?

5 ビュー (過去 30 日間)
Cameron Spooner
Cameron Spooner 2016 年 8 月 16 日
編集済み: Azzi Abdelmalek 2016 年 8 月 16 日
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.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 8 月 16 日
編集済み: Azzi Abdelmalek 2016 年 8 月 16 日
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,:)]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by