필터 지우기
필터 지우기

Changing plot in app designer

조회 수: 27 (최근 30일)
gravy
gravy 2024년 2월 4일
댓글: gravy 2024년 2월 7일
Hello everyone, can't solve the following problem in app designer. I have 3 buttons and a plot which will display graphs. It is necessary that when one of the graphs is drawn, when pressing another button, the first one stops and the next one starts from the same point where the first one ended. And it's the same with the third button.
here's the code for how I draw the graphs:
% Button pushed function: Button
function ButtonPushed(app, event)
a=0:pi/100:2*pi;
b=sin(a);
h = plot(app.UIAxes,a,b);
hold(app.UIAxes, 'on')
grid(app.UIAxes, 'on')
xlim(app.UIAxes, [0 15])
ylim(app.UIAxes, [-2 2])
for k = 1:numel(b)
set(h,'XData', a(1:k), 'YData', b(1:k))
drawnow(); pause(0.1)
end
end
% Button pushed function: Button2
function Button2Pushed(app, event)
a=0:pi/100:2*pi;
b=cos(a);
h = plot(app.UIAxes,a,b);
hold(app.UIAxes, 'on')
grid(app.UIAxes, 'on')
xlim(app.UIAxes, [0 15])
ylim(app.UIAxes, [-2 2])
for k = 1:numel(b)
set(h,'XData', a(1:k), 'YData', b(1:k))
drawnow(); pause(0.1)
end
end
% Button pushed function: Button3
function Button3Pushed(app, event)
a=0:0.1:2*pi;
b=[0:0.01:0.62];
h = plot(app.UIAxes,a,b);
hold(app.UIAxes, 'on')
grid(app.UIAxes, 'on')
xlim(app.UIAxes, [0 15])
ylim(app.UIAxes, [-2 2])
for k = 1:numel(b)
set(h,'XData', a(1:k), 'YData', b(1:k))
drawnow(); pause(0.1)
end
end

답변 (1개)

Benjamin Kraus
Benjamin Kraus 2024년 2월 4일
편집: Benjamin Kraus 2024년 2월 4일
I believe that you will need to leverage something like a timer to accomplish this goal.
Check-out this example on our doc pages: Use Timer to Plot Data Periodically in an App
You can start with that example with a single button and a single timer callback function. Once you get that working, you want to:
  • Add a property to your app that stores the "current time", that can be incremented as your timer executes.
  • Add a property to your app to indicate what data to plot, or what button was pressed last. You can use a single timer, with a single callback function, but the callback function will change behavior based on the last button pressed.
  • When you press a button, you can start and/or stop the timer, or change the value of the property on the app to control what data is being plotted.
  댓글 수: 3
Benjamin Kraus
Benjamin Kraus 2024년 2월 7일
편집: Benjamin Kraus 2024년 2월 7일
Do you want to elaborate on why it didn't help?
gravy
gravy 2024년 2월 7일
As I understand the timer pauses until I turn it off. I have 3 graphs with a changing value of Y, that is, at the moment of transition between buttons it will change every time, and how to do this through the timer I do not understand.
So far I'm trying to do it all through loops.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by