how to run a function again and again till a condition satisfies?

3 ビュー (過去 30 日間)
suchismita
suchismita 2015 年 4 月 27 日
コメント済み: suchismita 2015 年 4 月 27 日
Hello, i have a function which i want to run again and again till the condition is fulfilled.
please please help me....

採用された回答

Mischa Kim
Mischa Kim 2015 年 4 月 27 日
suchismita, see e.g.,
flag = false;
cnt = 0;
while ~flag
cnt = cnt + 1;
fprintf('Try no.: %d\n', cnt);
if (rand() < 0.25)
flag = true;
end
end
Your function would simply reside inside the loop.

その他の回答 (1 件)

Stephen23
Stephen23 2015 年 4 月 27 日
編集済み: Stephen23 2015 年 4 月 27 日
This is what a while loop is for. There are good examples in the documentation too:
And this is a good place to look when you want to control your program somehow:

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by