While loop with all elements meeting the conditions

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

采纳的回答

Davide Masiello
Davide Masiello 2022-10-28
编辑:Davide Masiello 2022-10-28
t = -100:200;
F = t;
indices = 1:100;
while all(F(indices)<0)
indices = indices + 1;
end
  4 个评论
Davide Masiello
Davide Masiello 2022-10-28
Yes, @Torsten is correct, I did not properly understand the question before.

请先登录,再进行评论。

更多回答(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