How to split a cell array into individual rows

9 ビュー (過去 30 日間)
KostasK
KostasK 2021 年 9 月 9 日
編集済み: Walter Roberson 2021 年 9 月 9 日
I have a cell array of the following format:
C =
2×2 cell array
{3×2 double} {3×18 sym}
{5×2 double} {5×18 sym}
I would like to split that cell array such that the row of within each cell becomes an individual cellarray row:
C =
8×2 cell array
{1×2 double} {1×18 sym}
{1×2 double} {1×18 sym}
{1×2 double} {1×18 sym}
... ...
However I am not able to find a way to perform the above. Any help would be appreciated.

採用された回答

Walter Roberson
Walter Roberson 2021 年 9 月 9 日
編集済み: Walter Roberson 2021 年 9 月 9 日
C = {randi(9,3,2), sym(randi(9,3,18)); randi(9,5,2), sym(randi(9,5,18))}
C = 2×2 cell array
{3×2 double} {3×18 sym} {5×2 double} {5×18 sym}
temp = cellfun(@(c) num2cell(c,2), C, 'uniform', 0);
temp2 = arrayfun(@(IDX) vertcat(temp{:,IDX}), 1:size(temp,2), 'uniform', 0);
newC = horzcat(temp2{:})
newC = 8×2 cell array
{[5 7]} {1×18 sym} {[2 7]} {1×18 sym} {[9 5]} {1×18 sym} {[2 3]} {1×18 sym} {[2 7]} {1×18 sym} {[3 1]} {1×18 sym} {[5 9]} {1×18 sym} {[4 2]} {1×18 sym}

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by