Combine two matrices into one

1 回表示 (過去 30 日間)
Mario Grgic
Mario Grgic 2020 年 4 月 26 日
回答済み: Sriram Tadavarty 2020 年 4 月 26 日
I have two matrices A and B and i want them to compain into a new matrix. The number of rows for matrices A and B are always 20, and only the number of column can change but it is the same for both( for instance if A is [20x50] then B is also [20x50]).
I want them to combine into a new matrix C so that the first row of matrix C is the first row of matrix A and the second row of matrix C is the first row of matrix B.
For example:
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40]
B = [41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60; 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80]
C = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60;
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40; 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80]
Thank you

採用された回答

Sriram Tadavarty
Sriram Tadavarty 2020 年 4 月 26 日
Hi Mario,
As far as A and B have same sizes, you can perform the following:
C = zeros(2*size(A,1),size(A,2));
C(1:2:end,:) = A;
C(2:2:end,:) = B;
Hope this helps.
Regards,
Sriram

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by