pliz help me to run a for loop for a specific run time for each iteration

10 ビュー (過去 30 日間)
rem ng
rem ng 2019 年 2 月 2 日
コメント済み: Saurabh Das 2021 年 5 月 18 日
help me please and thanks in advance!!! here i want to make each 'r' a specific time value for operation so that after that time next iteration will start. help me please anyone. your urgent response will help me lots.
ex: for r=1:rmax
if (some condition)
for i= 1:1:n
(some function)
end
end

採用された回答

Adam Danz
Adam Danz 2019 年 2 月 2 日
編集済み: Adam Danz 2019 年 2 月 3 日
In this example, your code is executed on each iteration and the while-loop waits for the remaining time to pass before entering the next iteration.
iterationTime = 2; %minimum number of seconds for each loop
for i = 1:10
tic; %set clock
fprintf('iteration %d\n', i) % <-- your code goes here
while toc < iterationTime %wait for the remaining iteration time
% do nothing %leave this empty
end
end
An alternative solution is to use a timer function (see link).
  5 件のコメント
rem ng
rem ng 2019 年 2 月 3 日
@Adam thanks. I got it now.
Saurabh Das
Saurabh Das 2021 年 5 月 18 日
@Adam Danz Thanks for very much for sharing this. It worked perfectly in my matlab script requirement.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by