Optimization plot in App Designer
5 views (last 30 days)
My App Designer program runs an optimization process. Specifically with the fmincon algorithm.
I would like to plot the real-time optimization process so that the user can watch it evolve. Specifically I want to plot 'optimplotx' and 'optimplotfval'.
However, I would like to plot these two graphs within two UIAxes elements in my App, and not in a pop-up window as it does by default.
My question is if it is possible to easily transfer those two plots that the optimization algorithm create (and updates) by default to their respective UIAxes elements.
By easily I mean not having to code all the plotting process (input data, plotting, updating...) but rather "associating" the actual graphs that pop-up to the UIAxes in the App.
Thanks in advance.
Kevin Holly on 2 Aug 2022
You could get the handle of the axes and transfer the children to the uiaxes in your app. See example code below:
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
nonlcon = @unitdisk;
A = ;
b = ;
Aeq = ;
beq = ;
lb = ;
ub = ;
x0 = [0,0];
options = optimoptions('fmincon','PlotFcn',@optimplotx);
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);
h = gca;
h.Children.Parent = app.UIAxes;
app.UIAxes.XLabel.String = h.XLabel.String;
app.UIAxes.YLabel.String = h.YLabel.String;
app.UIAxes.Title.String = h.Title.String;
app.UIAxes.XLim = h.XLim;
app.UIAxes.YLim = h.YLim;