Combining two matrices with different sizes

I have two matrices: M1(176x2x7) double and M2(369x2x27). The 176 column is 250:600 (interval of 2) and the 369 column is 230:598 (interval of 1). I would like the M1 to replace M2 (: , : ,1:7) and make sure the data is 0 for the odd numbers after the replacement for (: , : ,1:7). Could anyone please tell me how to do it.
Thank you very much!

6 件のコメント

David Hill
David Hill 2022 年 5 月 19 日
Replacement requires 5166 elements, M1 only has 2464 elements. How do you want to come up with the other elements?
Jan
Jan 2022 年 5 月 19 日
What does this mean: "The 176 column is 250:600 (interval of 2)"?
Cheuk Yin Wong
Cheuk Yin Wong 2022 年 5 月 19 日
Sorry for the confusion. I mean in the first column of M1, the number is from 250, 252, 254, ..., 598, 600. From 250 to 600, the interval between each number is 2.
Cheuk Yin Wong
Cheuk Yin Wong 2022 年 5 月 19 日
Thanks David, I would like the numbers of M1 1st column and 1st M2 column to match if there is data. If there is no data, fill the rest with zeros.
David Hill
David Hill 2022 年 5 月 19 日
A simple example would be helpful. What about the other columns? Are all the 1st columns of M1 in the 3rd dimension the same? (250:2:600)'
Cheuk Yin Wong
Cheuk Yin Wong 2022 年 5 月 22 日
The two matrices M1(176x2x7) (:,1,:) is from 250:600 with an increment of 2. M2 (:,1,:) is from 230:598 with an increment of 1. I would like the (:,1,:) of the two matrices to match (so both of them are 230:598 with an increment of 1 now), and replace M2 (:,:,1:7) with M1 to form a new M3 (369x2x27). For the mising data in M1, I would just like to fill these with 0. Sorry for the confusion - I hope this is clearer now.

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2022 年 5 月 19 日
編集済み: Matt J 2022 年 5 月 19 日

1 投票

M3=zeros(600,2,7);
M3(230:598,:,:)=M2;
M3(250:2:600,:,:)=M1; %replace M2 with M1
M3(1:2:end,:,:)=0;%odd numbers are zero

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeArgument Definitions についてさらに検索

製品

リリース

R2022a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by