how to merge 2 variable of different size?

8 Ansichten (letzte 30 Tage)
Suresh R
Suresh R am 3 Nov. 2021
Beantwortet: dpb am 3 Nov. 2021
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]

Antworten (1)

dpb
dpb am 3 Nov. 2021
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.

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by