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

조회 수: 2 (최근 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 CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by