How to compare column A and B based on the column C condition?
1 view (last 30 days)
Show older comments
Nayeon Kwon
on 11 Jun 2018
Commented: Star Strider
on 14 Jun 2018
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]
0 Comments
Accepted Answer
Star Strider
on 11 Jun 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Verification, Validation, and Test in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!