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]

回答(1 个)

dpb
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.

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by