Hold off in uitab does not seem to work?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I am trying to programmatically code a simple asset allocation app. I would like the efficient frontier and the associated asset returns to display in another tab, and if the user changes the expected returns, the efficient frontier is updated in the second tab.
The code below works, but the axes are not reset when the user changes the expected return, so the axes are overwritten as shown in the figure. It seems that the hold(ax,'off'); is not working. What am I doing wrong? I have also tried cla(ax,'reset') and ax=newplot(ax);
Example expected returns used as input were [0.23,0.15,0.11] and then [0.14,0.15,0.11].
Thank you!

function []=testApp()
function parButtonPushed(C)
ft=findobj(fig,'Tag','tab2');
er=findobj(fig,'Tag','er');
erData=table2array(er.Data);
tabg=findobj(fig,'Tag','tabg');
p=Portfolio('RiskFreeRate',0.001);
p = setAssetMoments(p,erData,C);
p = setDefaultConstraints(p);
ax = axes('parent',ft);
cla(ax, 'reset'); % also tried
ax=newplot(ax); % also tried
plotFrontier(ax,p,100);
hold(ax,'on');
scatter(sqrt(diag(C)),erData,20,'filled',"MarkerFaceColor",'#808080','Parent',ax);
hold(ax,'off');
tabg.SelectedTab=ft;
end
fig = uifigure;
fig.Position(3)=850;
fig.Position(4)=440;
movegui(fig,'center');
tabgp = uitabgroup(fig);
tabgp.Position(3)=650;
tabgp.Position(4)=340;
tabgp.Tag='tabg';
tab1 = uitab(tabgp,"Title","Expected Returns");
tab2 = uitab(tabgp,"Title", "Output");
tab2.Tag='tab2';
g = uigridlayout(tab1,[2,1]);
g.RowHeight = {99,22};
g.ColumnWidth = {'fit','fit'};
er=zeros(3,1);
C=[0.030766915 0.0252445 0.007653981;
0.0252445 0.049854359 0.011371085;
0.007653981 0.011371085 0.009284787];
t1=array2table(er,"VariableNames","Expected Return","RowNames",{'Asset 1','Asset 2','Asset 3'});
t11=uitable(g,"Data",t1);
t11.Tag='er';
t11.ColumnEditable = repelem(true,1);
btab1=uibutton(g,'Text','Continue',"ButtonPushedFcn", @(src,event) parButtonPushed(C));
btab1.Layout.Row=2;
btab1.Layout.Column = 1;
end
0 commentaires
Réponses (1)
Walter Roberson
le 22 Juil 2025
ax = axes('parent',ft);
Each time you execute that statment, you generate a new axes to plot in.
You instead need something like
ax = gca(ft);
gca() will fetch the current axes if one exists, and will otherwise create a new axes within the given parent.
3 commentaires
Voir également
Catégories
En savoir plus sur Graphics Object Programming dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!