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

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