Empty plot window pop up with App Designer

46 次查看(过去 30 天)
Hello,
I am a beginner using App Designer. I just finished coding a graphic interface, everything is going fine except that an empty figure popped up when I pushed the button to plot on the UIAxes of the interface.
I have already read some questions asked about this topic, but I have checked my code, and each time I'm plotting I am using app.UIAxes so the problem seems not to be exactly the same.
I also try to implement the following code :
fig1 = figure();
set(fig1, 'Visible', 'off'); % removes the default figure pop-up during live plot.
But it is not working. The purpose of the application is to calculate and plot the polynomial interpolation of data measurements. The same type of code is repeated for the different degrees of interpolation buttons. And for each button, the problem occurs. However, if I pushed the button for a degree and then to another, the empty figure popped up at the first action but not at the second one.
Please find below a part of my Matlab code :
if app.AcqButton==0
f = errordlg('Lauch Acquisition first !', 'Acquisition Error');
else
P3 = polyfit(app.N,app.x,3); % calcul de l'approximation polynomiale de degré 3
yfit = polyval(P3,app.N); %calcul les valeurs de l'approximation polynomiale pour chaque abscisse
cla(app.UIAxes);
cla(app.UITable);
CN=strings(1, app.InterpolDeg+1);
for k=1:4
CN(1,k)=strcat('a', num2str(k));
end
app.UITable.Data=P3;
app.UITable.ColumnName=CN;
fig1 = figure();
set(fig1, 'Visible', 'off'); % removes the default figure pop-up during live plot.
hold( app.UIAxes, 'on' ) %allows you to plot everything on the same figure without overwriting the curves
scatter(app.UIAxes,app.N,app.x,'blue');
plot(app.UIAxes,app.N,yfit,'r-.');
eqn = string(" Polynomial 3: y = " + P3(1)) + "x**3 + " + string(P3(2)) + "x**2 +" +string(P3(3))+ "x +" + string(P3(4));
text(app.UIAxes, min(app.N),max(app.x),eqn,"HorizontalAlignment","left","VerticalAlignment","middle")
%hold( app.UIAxes, 'off' )
end
Thank you by advance for any help !

采纳的回答

chicken vector
chicken vector 2023-4-28
编辑:chicken vector 2023-4-28
Your problem is that you are apparently initialising a new empty figure for no reason.
Try to remove these two lines:
fig1 = figure();
set(fig1, 'Visible', 'off');
When you specify the axis of the plot with:
scatter(app.UIAxes, app.N, app.x, 'blue');
plot(app.UIAxes, app.N, yfit, 'r-.');
You are most probably referring to some already existing axis in the app.UIFigure of your application.
By doing fig1 = figure() you create a new figure but then you plot in the UIAxes of your application's UIFigure.
Moreover pay attention that UIAxes are Children of UIFigures, while Axes are Children of Figures.
These are two different things!
If you want your plot to appear in a new pop-up window you can do the following:
fig1 = figure;
ax = axes(fig1);
scatter(ax, app.N, app.x, 'blue');
plot(ax, app.N, yfit, 'r-.');
Otherwise just remove those two lines where you define your figure.
As a side-tip, you can initialise your figure using:
fig1 = figure('Visibile','Off');
If this doesn't solve your problem, try to share your code to have more insightful help.
  7 个评论
chicken vector
chicken vector 2023-4-28
编辑:chicken vector 2023-4-28
Okay now I understand and remeber having the same issue with uigetfile once.
To my knowledge, there is no elegant solution and you have already choosen my favourite among the ones listed in that question, so just ignore my previous advice.
Hélène
Hélène 2023-4-28
Very nice, thank you very much for your valuable advices ! Have a nice day !

请先登录,再进行评论。

更多回答(1 个)

Connor
Connor 2024-2-23
I also had a smiliar issue,
I realized that I had left Hold on /off between the function that was updating my axes.

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by