How to reshape a cell array of cell arrays

4 ビュー (過去 30 日間)
Alan
Alan 2012 年 4 月 6 日
I have a cell array that in turn is composed of cell arrays. I would like to collapse the cell array at the top level so that all cells are on the same level. The top level cell array is 1 x 10 and each of the 10 cells contain an N x 1 cell array where N is variable and not necessarily the same for each of the 10 original cells. What I would like to do is similar to the (:) syntax for arrays, so that I collapse the top dimension. Any help would be appreciated!

採用された回答

Kye Taylor
Kye Taylor 2012 年 4 月 6 日
I assume your 1-by-10 cell is just like the 1-by-10 cell C created with the commands
C = cell(1,10);
for i = 1:10
N = randi(100);
C{i} = num2cell(rand(N,1));
end
You can easily do what you're trying to do with the command
CNew = cat(1,C{:});
Like a hot bath and massage...
  2 件のコメント
Alan
Alan 2012 年 4 月 6 日
I like it! Thanks, Alan
Kye Taylor
Kye Taylor 2012 年 4 月 6 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Alan
Alan 2012 年 4 月 6 日
So this seems to work: B = arrayfun(@(x)cat(1,A{:,x}),1:size(A,2),'un',0); although B is still a 1x1 cell and I still have to reference it as B{1}{M} to get the cell (M) that I want.

カテゴリ

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