Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How do I create such matrix ? (please look at the thread for further details)

1 回表示 (過去 30 日間)
Derick Wong
Derick Wong 2014 年 1 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi,
Let say I have 2 matrix A and B.
A=[1 2 3;
4 5 6]
B=[7 8 9;
10 11 12]
How do I create a matrix that becomes
C=[1-0 2-7 3-8;
4-0 5-10 6-11]
And what will happen if I have n rows and m columns for both A and B?

回答 (2 件)

the cyclist
the cyclist 2014 年 1 月 3 日
B2 = [zeros(size(B,1),1) B(:,1:(end-1))];
C = A - B2;

Amit
Amit 2014 年 1 月 3 日
編集済み: Amit 2014 年 1 月 3 日
How about
C = A;
C(:,2:end) = A(:,2:end)-B(:,1:end-1);
This solution is for generalized (n*m) system.
  2 件のコメント
Derick Wong
Derick Wong 2014 年 1 月 3 日
Hi, may I know what if I have n rows and m columns for both A and B?
Amit
Amit 2014 年 1 月 3 日
The solution written here will work for n rows and m columns system as well.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by