Combine two cell array of different dimension
17 ビュー (過去 30 日間)
古いコメントを表示
Gopalakrishnan venkatesan
2015 年 5 月 7 日
コメント済み: Shlomo David Sherer
2024 年 8 月 22 日
I have a two cell array A = {1,2}, B={4;5;6}
I need the result as one single array C = { 1 2 4
5
6 }
How it can be done?
Thank you
1 件のコメント
Guillaume
2015 年 5 月 7 日
編集済み: Guillaume
2015 年 5 月 7 日
If your cell arrays only contain scalar values, why are you bothering with cell arrays instead of the much faster and easier to use plain matrices?
Furthermore, it's unclear what output you want. Note that:
C = { 1 2 4
5
6 }
is not valid matlab syntax.
採用された回答
Thomas Koelen
2015 年 5 月 7 日
編集済み: Thomas Koelen
2015 年 5 月 7 日
A={1,2};
B={4,5,6};
C=cat(2,A,B)
C =
[1] [2] [4] [5] [6]
2 in cat is the direction you want to concatenate in, 1 does it vertically, which doesn't work because the cell doesn't have the same number of columns!
4 件のコメント
Thomas Koelen
2015 年 5 月 7 日
O, I didn't seee that! Must've thought it was a typo.
What you can do is:
A={1,2};
B={4;5;6};
C=cat(2,A,B')
C =
[1] [2] [4] [5] [6]
Like Guillaume said, there is no way to make a matrix or cell that's not a rectangle.
その他の回答 (2 件)
Sabarinathan Vadivelu
2015 年 5 月 7 日
編集済み: Sabarinathan Vadivelu
2015 年 5 月 7 日
Try this
A = {1,2};
B = {3, 5, 6};
C = horzcat(A, B)
ans =
C = {1 2 3 5 6}
3 件のコメント
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!