# How to subtract corresponding elemets of corresponding columns of two matrices?

1 ビュー (過去 30 日間)
Nisar Ahmed 2021 年 8 月 27 日
コメント済み: Nisar Ahmed 2021 年 8 月 27 日
Hi,
I have two matrices, say a = [P1 P2 P3], while size of each (P1, P2, P3) is i.e size(P1) = 100 1, etc.
similarly other matrix b = [Q1 Q2 Q3], while size of each (Q1, Q2, Q3) is i.e size(Q1) = 100 1, etc.
I want to differentiate a - b in such a way that each element of fisrt column P1 is being subtracted from corresponding elemt of Q1 and similarly
each column of fisrt column P2 is being subtracted from corresponding elemt of Q2 and so on....
How can I write its code?

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

### 採用された回答

Awais Saeed 2021 年 8 月 27 日
"each column of fisrt column P1 is being subtracted from corresponding elemt of Q1". That's a confusion. You meant rows, right? If you want to subtract matrix a and b, then why not just do
a - b;
##### 1 件のコメント表示非表示 なし
Nisar Ahmed 2021 年 8 月 27 日
@Awais Saeed actually it is each element of fisrt column P1 is being subtracted and I corrected now. Yes, simple a - b works

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

### Community Treasure Hunt

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

Start Hunting!