MATLAB Answers

How to continue a plot in app designer with a push button?

26 views (last 30 days)
Davide Mastrodicasa
Davide Mastrodicasa on 24 Jan 2020
Commented: Davide Mastrodicasa on 27 Jan 2020 at 14:54
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 Comments

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 24 Jan 2020 at 21:18
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.

  1 Comment

Davide Mastrodicasa
Davide Mastrodicasa on 27 Jan 2020 at 14:54
Geoff,
Thank you very much for your suggestion. I solved the problem following your answer.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2019a