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!