MATLAB: How to display @gaplotpareto output in UIAxes within app designer

app designergamultiobjgaparetoplot

Hi, I am using app designer with gamultiobj function to solve an optimization problem with 2 objectives.
I have modified @gaplotpareto.m to display at desired UIAxes.
But when runing the app designer function that calls the optimization, it stops because does not identify the function in bold:
function state = gaplotpareto1(app,options,state,flag)
%GAPLOTPARETO1 Plots a Pareto front for first two objectives.
%
%if nargin < 4 || isempty(objectivesToPlot)
objectivesToPlot = [1 2];
%end
markers = {'og','pm','sb','dk','hr','xc'};
subPops = populationIndices(options.PopulationSize);
[~,c] = size(subPops);
for i = 1:c
pop = subPops(:,i);
range = pop(1):pop(2);
tag = ['gaplotPareto',int2str(i)];
app.plotFirstFront(state.Score(range,:),state.Rank(range),markers{1 + mod(i,5)},objectivesToPlot(:)',flag,tag);
hold(app.UIAxes4,"on")
end
title(app.UIAxes4,'Pareto front','interp','none')
hold(app.UIAxes4,"off")
end
subPops = populationIndices(options.PopulationSize);
I have sougt the function in matlab documentation, but I could not find anything about this function.
As an alternative, do you have other alternative to display pareto in a desired UIAxes inside App Designer while running optimization?
Thank you!

Best Answer

Don't pass app handles to the OutputFcn as weird interactions happen when you want to run save or exportapp, it makes overall things slower at least in my case.
Set a tag, or a unique name for your app in Component Browser, under UIFigure - Identifiers, and get its handle this way:
% in gaplotpareto1
app = get(findall(0, 'Tag', 'AppUIFigure'), 'RunningAppInstance');
ax = app.UIAxeshandle; % change this to your uiaxes handle in App Designer
% replace plot commands by adding handle
% plot(ax, x, y)
You need to call your OutputFcn this way, don't worry about not having declared these variables, since they are handled by the solver.
'OutputFcn', @(options, state, flag,objectivesToPlot)gaplotpareto1(options,state,flag,objectivesToPlot)