How do I get a for loop to check a row for conditions?

5 views (last 30 days)
Hey Everyone: I'm going to try and phrase this as best I can, I'm quite new to matlab and coding but I need help with this vital skill.
I want to write a for loop that checks multiple conditions:
This is my Matrix I will analyse.
[170 284 60
292 380 69
294 397 82]
I want to check if element 1 is greater than some number, element 2 is greater than some number and element 3 is greater than some number. I also want it to check row by row and tell it to consider [170 284 60] as row 1, [292 380 69] as row 2 and [294 397 82] is row 3.
Can anyone help me out?

Accepted Answer

Ilian
Ilian on 8 Apr 2020
If you want to use a for loop, you could have a look at if statement with multiple conditions
% Your conditions
a = 200;
b = 200;
c = 80;
A = [170 284 60; 292 380 69; 294 397 82];
for i = 1:3
if A(i,1) > a && A(i,2) > b && A(i,3) > c
disp(A(i,:)) % display rows that fulfill all conditions.
end
end

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!