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 Center および File ExchangeGet Started with Simulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by