how to merge 2 variable of different size?
조회 수: 3 (최근 30일)
이전 댓글 표시
how to merge 2 variable of different size? where size of A is 1X5 'double' and size of B is 2X10 'double'.
A = [1,2,3,4,5] '1 x 5 double'
b = [6 7
8 9
10 11
12 13
14 15
16 17
18 19
20 21
22 23
24 25]
댓글 수: 0
답변 (1개)
dpb
2021년 11월 3일
With what expected as result, pray tell?
You can't have a 2-column matrix of 25-elements; you could keep the two as elements in a cell array (not particularly recommended, but possible, and the choice if there's going to be a need to identify those elements from A again later).
C=[A(:);b(:)];
returns a column vector; you can reshape() it by prime factors if wanted.
Alternatively, one could augment and reshape the first to have two columns -- but that will require A having an even number of elements to do so, either by adding (or removing) an odd number first.
C=[reshape([0 A],2,[]);b];
is one possible solution of any number in that vein.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!