Reformatting cell arrays of cell arrays

조회 수: 7 (최근 30일)
Terry
Terry 2013년 11월 28일
댓글: Terry 2013년 11월 29일
Apologies for what seems to be a very simple question, but I’m having trouble reformatting a cell array and I’m sure there’s a much smarter way of dealing with the problem than creating a loop.
I’ve managed to get myself a cell array in the format:
c =
{2x1 cell}
{2x1 cell}
{2x1 cell}
Which is a 3x1 cell array of 2x1 cell arrays containing strings when ideally I would like to have a 3x2 cell array of strings. Is anyone able to help please?
Please note that I have simplified this problem, I'm really after a solution to when there is an nx1 cell array of mx1 cell arrays.
Ultimately, I'm wanting to create a dataset array so perhaps the ideal solution would create a 1xm cell array of nx1 cell arrays! ie the solution to the above would be:
Newc =
{3x1 cell} {3x1 cell}
any ideas on how to do this also?
Thanks for any help which points me in the right direction.
Terry

채택된 답변

Simon
Simon 2013년 11월 29일
Hi!
Try
C{1, 1} = {'11'; '12'};
C{2, 1} = {'21'; '22'};
C{3, 1} = {'31'; '32'};
Rows = 3;
Columns = 2;
CO = reshape([C{:}], Columns, Rows).';
Newc = cell(1, Columns);
for n = 1:Columns
Newc{n} = {CO{:, n}}.';
end
  댓글 수: 1
Terry
Terry 2013년 11월 29일
Genius! Thank you very much for your help.

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

추가 답변 (0개)

카테고리

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