Empty plot window pop up with App Designer

46 views (last 30 days)
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 !

Accepted Answer

chicken vector
chicken vector on 28 Apr 2023
Edited: chicken vector on 28 Apr 2023
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 Comments
chicken vector
chicken vector on 28 Apr 2023
Edited: chicken vector on 28 Apr 2023
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 on 28 Apr 2023
Very nice, thank you very much for your valuable advices ! Have a nice day !

Sign in to comment.

More Answers (1)

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

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!