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!