Combine two cell array of different dimension
조회 수: 44 (최근 30일)
이전 댓글 표시
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
채택된 답변
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!