Arrange and merge cell data

조회 수: 1 (최근 30일)
Isma_gp
Isma_gp 2016년 9월 14일
댓글: Walter Roberson 2016년 9월 16일
Hi,
I have a 3x3 cell as follows: [[1x40], [1x40], [1x40] ; [1x30], [1x30] ,[1x30] ; [1x50], [1x50] ,[1x50] ]
I would like to arrange the data, so that the final result is a 1x3 cell: [[3x40];[3x30];[3x50]]
I would like to do this without calling each cell specifically (in reality this is for a 20x20 cell)
Thanks

채택된 답변

Walter Roberson
Walter Roberson 2016년 9월 14일
arrayfun(@(col) vertcat(YourCell{:,col}), 1:size(YourCell,2), 'Uniform', 0)
  댓글 수: 2
Isma_gp
Isma_gp 2016년 9월 16일
Hey, Thanks for your answer. The vertical concatenation is not working because the dimension of the cells in each row is different i.e. 30,40 and 50
Walter Roberson
Walter Roberson 2016년 9월 16일
arrayfun(@(row) vertcat(YourCell{row,:}), (1:size(YourCell,1)).', 'Uniform', 0)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Stephen23
Stephen23 2016년 9월 16일
편집: Stephen23 2016년 9월 16일
C = {...
rand(1,40),rand(1,40),rand(1,40);...
rand(1,30),rand(1,30),rand(1,30);...
rand(1,50),rand(1,50),rand(1,50)};
%
D = cellfun(@(c)vertcat(c{:}),num2cell(C,2),'UniformOutput',false);
and tested:
>> size(D{1})
ans =
3 40
>> size(D{2})
ans =
3 30
>> size(D{3})
ans =
3 50

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by