필터 지우기
필터 지우기

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 CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by