Matlab app designer isn't plotting on the UI axes, and actually isn't plotting any results at all.

12 次查看(过去 30 天)
I have a function assigned for when the button is pushed; the code looks like this:
function FirewhenreadyButtonPushed(app, event)
c=299792458;
if app.ExcitationShapeDropdown.Value=="Gaussian"
gaussian=1;
else
gaussian=0;
end
if app.IonizationShapeDropdown.Value=="Gaussian"
gaussianIon=1;
else
gaussianIon=0;
end
if app.AtomDropDown.Value=="Sr I"
A=2.01e8;
w0=4.087e15;
elseif app.AtomDropDown.Value=="Rb I"
A=0;
w0=0;
end
s0=1e-11;
t=app.TimeField.Value*10^-9;
diameter=app.ExcitationDiameterField.Value*10^-3;
energy=app.ExcitationEnergyField.Value*10^-6;
monkey=app.ExcitationDurationField.Value*10^-9;
delta=2*pi*c/(app.ExcitationWavelengthField.Value*10^-9)-w0;
IonE=app.IonizationEnergyField.Value*10^-6;
Ionmonkey=app.IonizationDurationField.Value*10^-9;
Iondiameter=app.IonizationDiameterField.Value*10^-3;
bandwidth=app.ExcitationBandwidthField.Value/(2*pi);
[time,P]=RK4BlochGUI(s0,t,diameter,energy,monkey,delta,A,w0,IonE,Ionmonkey,Iondiameter,bandwidth,gaussian,gaussianIon);
plot(app.UIAxes,time,P(1,:),'c')
hold on
plot(app.UIAxes,time,P(2,:),'g')
plot(app.UIAxes,time,P(3,:),'k')
hold off
end
There is no issue with the outside function called. Outside of app designer, it works perfectly well, and plotting it goes without a hitch.
But even when I change the code to something like this:
x=linspace(1,10);
y=3*x;
scatter(app.UIAxes,x,y);
it still won't plot. This looks correct; what the heck is going on?
  1 个评论
VBBV
VBBV 2023-6-12
移动:VBBV 2023-6-20
can you explain your question more clearly? what is section of below code got to do with code present in function ? They appear to be unrelated. Do you see graphs on plotting axes when you press the pushbutton ? if possible can you share the code ?
x=linspace(1,10);
y=3*x;
scatter(app.UIAxes,x,y);

请先登录,再进行评论。

回答(1 个)

Sandeep Mishra
Sandeep Mishra 2023-6-15
Hello William,
I understand that you are trying to plot three graphs using UIAxes in app designer.
In MATLAB, "hold(ax,_)" function can be used to hold the state of "ax" axes and in the second parameter you can set 'on' or 'off'.
You can implement your plotting function similar to the below example
% Plot1
t = [1 2 3 4 5 6 7 8];
z = [2 3 4 5 6 7 8 9];
plot(app.UIAxes, t,z,'c');
% Plot2
hold(app.UIAxes, 'on')
g = [1 2 3 4 5 6 7 8];
h = [3 4 5 6 7 8 9 10];
plot(app.UIAxes, g,h,'g');
% Plot3
c = [1 2 3 4 5 6 7 8];
d = [0 1 2 3 4 5 6 7];
plot(app.UIAxes, c,d,'k');
hold(app.UIAxes, 'off')
You can refer to the below documentation to learn more about "hold" in MATLAB

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by