Interrupting GUI during optimization
显示 更早的评论
Hi, I'm designing an app with appdesigner that runs an optimization process. I'm trying to put in a push button that would interrupt the optimization because it can sometimes be quite lengthy. Here is my code:
% Button pushed function: SolveButton
function Solve(app, event)
Objective= @(x) MultiObjectiveFun(x,Ar,BODmin,BODmax,Ecoli_min,Ecoli_max,Ecoli_objective,BOD_objective,Depth1,Depth2,Depth3,Depth4);
A = [];
B = [];
Aeq = [];
Beq = [];
LB= [20 20 20 ];
UB= [60 60 60];
[a]=gamultiobj(Objective,3,A,B,Aeq,Beq,LB,UB);
end
This function would be the callback to stop the optimization: % Button pushed function: StopButton
function Stop(app, event)
end
I've tried a few things but can't seem to get it to interrupt the optimization. I would like it to end the optimization completely. Allowing me to change the inputs and then press solve again to restart. I don't know where to write in my pause or how to write in my stop button.
回答(1 个)
Alan Weiss
2018-6-18
You need to add an output function option to your gamultiobj call, and the callback should look something like this:
function [state,options,optchanged] = gaoutfun(options,state,flag)
optchanged = false;
if stopbutton % put your test for the stop button here
state.StopFlag = 'y'
end
Alan Weiss
MATLAB mathematical toolbox documentation
3 个评论
Francois Daudelin
2018-6-18
编辑:Walter Roberson
2018-6-18
What does "I added a private function" exactly mean? The error message means, that it cannot be found in the path.
Of course "if stopbutton==1" was pseudo-code. You have to implement this by your own. We cannot guess how you have implemented the button for stopping. But you have to insert the check of the state of the button here. Maybe the button sets a flag in the ApplicationData of the figure (see: setappdata). Defining the variable stopbutton is not sufficient, because it is not visible from the outside.
Walter Roberson
2018-6-18
It cannot find the function gaoutfun for some reason.
Are you using nested functions with stopbutton being a shared variable?
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!