How to compare column A and B based on the column C condition?

1 回表示 (過去 30 日間)
Nayeon Kwon
Nayeon Kwon 2018 年 6 月 11 日
コメント済み: Star Strider 2018 年 6 月 14 日
Hello, I am a beginner at Matlab.
If I want to compare columnes A and B when column C is satisfied with the condition.
for example, in the following matrix,
in case of A(:, 3) == 1,
comparing A(:, 1) to A(:,2) is my goal. How shoud I do?
A = [1 7 0; 4 2 1;8 2 1; 2 4 1; 9 4 0]

採用された回答

Star Strider
Star Strider 2018 年 6 月 11 日
Try this:
A = [1 7 0; 4 2 1;8 2 1; 2 4 1; 9 4 0];
C3 = A(:,3) == 1; % Logical Vector For Rows Meeting Condition
Compare = A(C3,1) ./ A(C3,2) % ‘Compare’ By Division
Use any method for comparing them that you want. I chose element-wise division here to demonstrate the approach.
Experiment to get the result you want.
  2 件のコメント
Nayeon Kwon
Nayeon Kwon 2018 年 6 月 14 日
Thank you. I solved my problem with this hint!
Star Strider
Star Strider 2018 年 6 月 14 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVerification, Validation, and Test についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by