how can i combine contents of two cell arrays into one cell array of same length
1 回表示 (過去 30 日間)
古いコメントを表示
I have two cell arrays
Bill = {[1 2 3 4 5];[2 4 6 8 10]};
Ted = {[6 7 8 9 10];[12 14 16 18 20]};
and I want to merge them together so that
Excell = {[1 2 3 4 5 6 7 8 9 10]; [2 4 6 8 10 12 14 16 18 20]};
the only thing I can think of to combine them is
Excell = cellfun(@(v,w) [v,w],Bill,Ted,'UniformOutput',0)
but I imagine that there is a better more compact way to do this
thanks
0 件のコメント
採用された回答
Geoff Hayes
2014 年 11 月 14 日
Joshua - I think that your solution works well. An alternative is the following
Excell = mat2cell(cell2mat([Bill , Ted]),[1 1]);
where we just combine the two cell arrays as [Bill , Ted] and then convert it to a 2x10 matrix with cell2mat. We then convert back to a cell array as mat2cell(...,[1 1]) where we use the [1 1] to indicate the row dimensions of the new cell array.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!