While loop with all elements meeting the conditions

1 visualización (últimos 30 días)
Niklas Kurz
Niklas Kurz el 28 de Oct. de 2022
Comentada: Niklas Kurz el 28 de Oct. de 2022
How do I set a while loop that runs until all elements meet the condition? For instance:
t = -100:200;
F = t;
indices = 1:100;
while F(indices) < 0 %
indices = indices + 1;
end
This while-loop only will run, until one of the elements of F(indices) will be creater than 0. However I wish it will run until all of the elements will meet the condition. How to implement this?

Respuesta aceptada

Davide Masiello
Davide Masiello el 28 de Oct. de 2022
Editada: Davide Masiello el 28 de Oct. de 2022
t = -100:200;
F = t;
indices = 1:100;
while all(F(indices)<0)
indices = indices + 1;
end
  4 comentarios
Davide Masiello
Davide Masiello el 28 de Oct. de 2022
Yes, @Torsten is correct, I did not properly understand the question before.
Niklas Kurz
Niklas Kurz el 28 de Oct. de 2022
Awesome, thank you so much!

Iniciar sesión para comentar.

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