Interrupting GUI during optimization
Afficher commentaires plus anciens
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.
Réponses (1)
Alan Weiss
le 18 Juin 2018
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 commentaires
Francois Daudelin
le 18 Juin 2018
Modifié(e) : Walter Roberson
le 18 Juin 2018
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
le 18 Juin 2018
It cannot find the function gaoutfun for some reason.
Are you using nested functions with stopbutton being a shared variable?
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!