フィルターのクリア

Alternating equations every other row

3 ビュー (過去 30 日間)
Sha S
Sha S 2015 年 7 月 15 日
編集済み: Andrei Bobrov 2015 年 7 月 15 日
I have A= [3 2 1, 3 8 2, 3 9 2, 9 5 1, 3 8 3, 7 4 2]
For the first row I would like to subtraction Column 2 from Column 1, then for row I want to subtract Column 1 from Column 2. I want these two equations to alternate when going through the rows. In the end I want something that looks like this:
B= [1, 5, -6, -4, -5, 3]
Thanks!
  1 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 15 日
There is one row in A, maybe you mean
A=[3 2 1; 3 8 2; 3 9 2; 9 5 1; 3 8 3; 7 4 2]
You should explain how you get B. what is row I?

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2015 年 7 月 15 日
編集済み: Andrei Bobrov 2015 年 7 月 15 日
B = diff(A(:,[1,2]),1,2).*(-1).^(1:size(A,1))'

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 15 日
編集済み: Azzi Abdelmalek 2015 年 7 月 15 日
A= [3 2 1;3 8 2; 3 9 2;9 5 1; 3 8 3; 7 4 2]
sg=ones(size(A,1),1)
sg(2:2:end)=-1
(A(:,1)-A(:,2)).*sg

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by