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

4 次查看(过去 30 天)
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?

采纳的回答

Ilian
Ilian 2020-4-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by