how to merge 2 variable of different size?

4 ビュー (過去 30 日間)
Suresh R
Suresh R 2021 年 11 月 3 日
回答済み: dpb 2021 年 11 月 3 日
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 Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by