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

7 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Geoff Hayes
Geoff Hayes el 24 de En. de 2020
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 comentario
Davide Mastrodicasa
Davide Mastrodicasa el 27 de En. de 2020
Geoff,
Thank you very much for your suggestion. I solved the problem following your answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by