フィルターのクリア

How to stop a function after specified time?

5 ビュー (過去 30 日間)
Hao Sun
Hao Sun 2020 年 4 月 16 日
回答済み: Walter Roberson 2020 年 4 月 16 日
I want to stop a function after some time without modifying it (when calling the function set a specified time)
i.e. runfor10min(somefunction())

回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 4 月 16 日
You will need to use the Parallel Computing Toolbox, and start a parallel pool with one member (and you would probably want to increase numthreads in the pool.) Then you would parfeval(), creating a "future" and which would proceed to run independently. In the client, you would monitor to see whether the future had completed, or whether the 10 minutes had elapsed. If the time had elapsed, then cancel() the future.
Note: if the function is deep inside a library routine, it might take some time to cancel. Mathematical calls involving large arrays can encounter this, and some symbolic functions can encounter this.

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

タグ

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by