Empty plot window pop up with App Designer

조회 수: 53 (최근 30일)
Hélène 2023년 4월 28일
답변: Connor 2024년 2월 23일
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');
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
CN=strings(1, app.InterpolDeg+1);
for k=1:4
CN(1,k)=strcat('a', num2str(k));
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
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' )
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 2023년 4월 28일
Very nice, thank you very much for your valuable advices ! Have a nice day !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

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에서 Interactive Control and Callbacks에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by