subtract different column by different number

3 ビュー (過去 30 日間)
Patrick
Patrick 2014 年 10 月 1 日
コメント済み: Patrick 2014 年 10 月 1 日
I have a 1000x3 matrix. I want to subtract different column from different number. For example, the first column elements will all be subtracted from 10, those in the second column will be subtracted from 2, the third column will be subtracted from 3.
Any good ways to do this? Thanks a lot!

採用された回答

Mischa Kim
Mischa Kim 2014 年 10 月 1 日
Patrick, use bsxfun:
A = [1 2 10; 1 4 20; 1 6 15];
A
A =
1 2 10
1 4 20
1 6 15
B = bsxfun(@minus, [1 2 3], A)
B =
0 0 -7
0 -2 -17
0 -4 -12
  1 件のコメント
Patrick
Patrick 2014 年 10 月 1 日
Thank you Kim!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by