How I can create a while cycle that ends after a sepecific time

조회 수: 4 (최근 30일)
Dario Furnari
Dario Furnari 2023년 1월 3일
답변: Eric Sofen 2023년 1월 4일
my aim is make a wile cilce that run for a specific time T. For exemple
T=60 %sec
while(t==60)
t=time.
for i=0:10
d=sum(i+)
.
.
.
.
.
.
end
end
%where t start from zero and go on whit the time
%t is 1 after 1 second

채택된 답변

Sylvain
Sylvain 2023년 1월 3일
tic
while(toc<60)
  % code
end

추가 답변 (1개)

Eric Sofen
Eric Sofen 2023년 1월 4일
I think timer is likely to give you better precision for this sort of thing than tic/toc (tic/toc is better for timing performance of a function or script). The reference page for timer illustrates exactly this while-loop scenario.

카테고리

Help CenterFile Exchange에서 Get Started with Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by