How do I get a for loop to check a row for conditions?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Ilian
le 8 Avr 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!