MATLAB Answers

'Merge' two cell arrays into one single cell array (NOT concatenation!)

3 ビュー (過去 30 日間)
Ku
Ku 2021 年 8 月 8 日
コメント済み: Ku 2021 年 8 月 8 日
Dear All,
I am not familiar with cell array and have one simple question as follows-
There are two 1x2 cell arrays, for c1={1;2 5} , and c2= {3;4 6;7;8;9;10}.
Now I need to create a new 1x2 cell array c3 that = {1;2;3;4 5;6;7;8;9;10}.
I've tried concatenate but it returned as a 2x2 cell array
My code c3=cat(1,c1,c2)
Please let me know how to do this correctly, any advice would be appreciated!
K

採用された回答

Stephen
Stephen 2021 年 8 月 8 日
c1 = {[1;2],5}
c1 = 1×2 cell array
{2×1 double} {[5]}
c2 = {[3;4],[6;7;8;9;10]}
c2 = 1×2 cell array
{2×1 double} {5×1 double}
out = cellfun(@vertcat,c1,c2,'uni',0)
out = 1×2 cell array
{4×1 double} {6×1 double}
celldisp(out)
out{1} = 1 2 3 4 out{2} = 5 6 7 8 9 10
  1 件のコメント
Ku
Ku 2021 年 8 月 8 日
Thank you so much! That works wonderfully.

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by