필터 지우기
필터 지우기

how to terminate loop when i get desired result

조회 수: 2 (최근 30일)
ravi shukla
ravi shukla 2021년 6월 25일
편집: KSSV 2021년 6월 25일
i am sloving a matrix, which is in time loop (for). I want this time loop stop and present final output once the output matrix starts repeating itself.

답변 (1개)

KSSV
KSSV 2021년 6월 25일
편집: KSSV 2021년 6월 25일
t0 = randperm(100,1) ; % give some value
tol = 10^-3 ; % mention the accuracy you want
for i = 1:10000
% find your output here
t1 = randperm(100,1) ; % random value for demo
if abs(t0-t1) < tol
break
else
t0 = t1 ;
end
end
[t0 t1 i]
ans = 1×3
28 28 75

카테고리

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