フィルターのクリア

While loop: value increases, break if not.

3 ビュー (過去 30 日間)
Miroslav Mitev
Miroslav Mitev 2017 年 11 月 20 日
コメント済み: Miroslav Mitev 2017 年 11 月 20 日
Is it possible to use while loop that checks if the variable is increasing each step and break if not?
Or I have to use for loop, something like this:
for i=2:N
if x(i-1)>x(i)
x(i)=0;
end
end

採用された回答

OCDER
OCDER 2017 年 11 月 20 日
You could use a while loop instead to run until a conditions is met, and it'll automatically break.
i = 2;
while x(i) <= x(i-1)
i = i+1;
end
Or, you could use a break statement.
for i = 2:N
if x(i) > x(i-1)
break
end
end
  1 件のコメント
Miroslav Mitev
Miroslav Mitev 2017 年 11 月 20 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by