Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
William Grant
William Grant el 8 de Abr. de 2020
Comentada: William Grant el 8 de Abr. de 2020
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?

Respuesta aceptada

Ilian
Ilian el 8 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by