How to terminate any sub function's execution within the main function?

When I am running a MATLAB function that time if I don’t want to wait for the any sub function result and I want to terminate the running of that sub function but at the same time my others sub function should give me the result and graph .
As a example :
function [………output………]= mainfun (input)
[…..output ….]=subfun1(input)
[…….output….]=subfun2(input)
#some plot
end
maybe for me my subfun2 is taking more time to give me the result that time I want to terminate this function after certain period of time and want to get the other functions result .

8 件のコメント

KSSV
KSSV 2022 年 6 月 27 日
Ifeach function is taking the same input and output of the subfunction is not fed into another subfunction, you can use parfor
Akash Pal
Akash Pal 2022 年 6 月 27 日
every subfun is taking the input from the same input source .But for the output they all are displaying different output .
KSSV
KSSV 2022 年 6 月 27 日
Explore parfor
Edric Ellis
Edric Ellis 2022 年 6 月 27 日
I think parfeval might be a better fit. That allows you to terminate things cleanly. Something like this:
fcns = {@subfun1, @subfun2, @subfun3};
for i = 1:numel(fcns)
fut(i) = parfeval(fcns{i}, 1, input);
end
for i = 1:numel(fut)
[idx, output] = fetchNext(fut);
if checkStuff(output)
% Got the output needed
cancel(fut);
break
end
end
Akash Pal
Akash Pal 2022 年 6 月 27 日
I tried your example but in my case it's showing error due to the lots of input parameters .
Walter Roberson
Walter Roberson 2022 年 6 月 27 日
Is it the sub-functions that are invoking the graphs, or does the main function do the graphing based on the results of the sub-functions ?
parfeval() and related functions cannot do graphics. If you need to do graphics with them, you need to set up parallel data queues to send information back to the main function to do the plotting on its behalf.
Akash Pal
Akash Pal 2022 年 6 月 27 日
the subfunctions are plotting the graph .
Walter Roberson
Walter Roberson 2022 年 6 月 27 日
https://www.mathworks.com/help/parallel-computing/parallel.pool.dataqueue.html

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2022 年 6 月 27 日

コメント済み:

2022 年 6 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by