How to continue a plot in app designer with a push button?
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone. I'm new in appdesigner and I need a help to solve this problem:
I have a for loop that plots me each column of a matrix and I would like to continue the plot with a push Button. From this link https://it.mathworks.com/matlabcentral/answers/473457-button-press-to-continue-iteration-in-appdesigner the possible solution seems to be uiwait and uiresume but I'm not able to use them properly.
This is my code:
function FRFOMACalculationButtonPushed(app, event)
% Code lines....
for ch = 1:size(app.H.H,1)
app.Panel.AutoResizeChildren = 'off';
ax1=subplot(3,1,[1 2],'Parent',app.Panel);
semilogy(ax1,app.H.f,abs(squeeze(app.H.H(ch,1,:))));
ylabel(ax1,'Magnitude'); xlim(ax1,[app.f1 app.f2])
ax2=subplot(3,1,3,'Parent',app.Panel);
plot(ax2,app.H.f,angle(squeeze(app.H.H(ch,1,:))));
xlabel(ax2,'f [Hz]'); ylabel(ax2,'Phase'); xlim(ax2,[app.f1 app.f2]);
uiwait(ax1);
uiwait(ax2);
end
% Code lines....
end
For the callback of the button i have:
function ButtonNextPushed(app, event)
uiresume(ax1);
uiresume(ax2);
end
It doesn't work and I don't know how to solve it.
I hope the question is clear. Thank you in advance.
0 个评论
采纳的回答
Geoff Hayes
2020-1-24
Davide - rather than waiting and resuming, since all subsequent updates to the axes occur with the press of a button, just put all that update logic in a helper function that is called by both FRFOMACalculationButtonPushed and ButtonNextPushed. Perhaps something like
function FRFOMACalculationButtonPushed(app, event)
% some code to do calculations?
% update the axes
app.H.ch = 1; % I'm not sure if this is valid (never used AppDesigner)
UpdatePlot(app);
end
function ButtonNextPushed(app, event)
UpdatePlot(app);
end
function UpdatePlot(app)
if app.H.ch <= size(app.H.H,1)
ch = app.H.ch;
app.Panel.AutoResizeChildren = 'off';
ax1=subplot(3,1,[1 2],'Parent',app.Panel);
semilogy(ax1,app.H.f,abs(squeeze(app.H.H(ch,1,:))));
ylabel(ax1,'Magnitude'); xlim(ax1,[app.f1 app.f2])
ax2=subplot(3,1,3,'Parent',app.Panel);
plot(ax2,app.H.f,angle(squeeze(app.H.H(ch,1,:))));
xlabel(ax2,'f [Hz]'); ylabel(ax2,'Phase'); xlim(ax2,[app.f1 app.f2]);
app.H.ch = app.H.ch + 1; % I'm not sure if this is valid (never used AppDesigner)
end
end
The above should avoid the need to use wait and resume. I'm just not sure on the syntax of updating variables in the app object. Perhaps the above is sufficient. If not, hopefully it is enough to get an idea of what you could do.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!