フィルターのクリア

How can I run a code for a pre-defined time duration?

3 ビュー (過去 30 日間)
carlo24
carlo24 2021 年 6 月 10 日
回答済み: Shadaab Siddiqie 2021 年 6 月 15 日
Hi everyone, how can I execute a code only for a limited time duration?
The problem arises since I've a very large database, in which only few elements seem to enter infinite loops (either in function1 or in function2, as reported below); to be thorough, the problem occurs in function1 or function2 at level of fmincon or ode15s, respectively.
The idea would be to run the code for all elements and for those precise elements entering infinite loop to move onto the next element once the limit of time duration is reached.
The code I've implemented is like the following:
for i=1:NumElem
...
function1;
...
function2;
...
end
I've already tried to implement something like this:
for i=1:NumElem
tic
while toc<300
...
function1;
...
function2;
...
end
end
But with no results since infinite loops occur inside function1 or function2.
Thanks in advance!!
  2 件のコメント
dpb
dpb 2021 年 6 月 10 日
編集済み: dpb 2021 年 6 月 10 日
Well, you'll have to (obviously?) make whatever changes you make inside your two functions and if it is ode15 or fmincon that are the actual functions in which the hangup occurs, you'll have to or use callbacks to create a deadman timer that interrupts the function.
I have an appointment right now but I think there are settable parameters in those that could be used to limit number of iterations for fmincon; I don't recall on ode routines otomh...
Mario Malic
Mario Malic 2021 年 6 月 10 日
MaxTime is the option for fmincon.

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

採用された回答

Shadaab Siddiqie
Shadaab Siddiqie 2021 年 6 月 15 日
From my understanding your functions are struck in infinite loop, and you want to stop this when it happens. You can resolve this using one of these ways:
  1. You can use different algorithms like 'interior-point' or 'sqp' algorithm. These algorithms have better safeguards against “Inf” and “NaN” values.
  2. You can set the "MaxSQPIter" property in the OPTIMSET function to a finite value. Ideally, it should be a multiple of the larger of the number of variables or number of constraints.
  3. You can use MaxIteration property of fmincon to stop the loop after certain number of iterations.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by