App Designer Plot Multiple Graph

조회 수: 12 (최근 30일)
Lee Xing Wei
Lee Xing Wei 2021년 4월 27일
댓글: Subhadeep Koley 2021년 4월 28일
I am new in App Designer, I want to plot multiple graph continue the time, like first time I push the button I get a graph from 0 to t1, then I push the button agian, the graph continue plot from t1 to t2.
The system does not regonize the undeclare t1 as 0, but if I declare t1 = 0, every time I push the button, the graph is overlapping.
function AddButtonPushed(app, event)
if(app.Button_2.Value)
f = 10;
elseif(app.Button2.Value)
f = 15;
elseif(app.Button3.Value)
f = 20;
end
if(app.Button_3.Value)
t = 1;
elseif(app.Button_4.Value)
t = 1/2;
elseif(app.Button_5.Value)
t = 1/4;
end
x = t1:0.0001:t1+t;
y = sin(2*pi*f*x);
t1 = t1+t;
hold(app.UIAxes);
plot(app.UIAxes,y);
hold(app.UIAxes);
end

채택된 답변

Subhadeep Koley
Subhadeep Koley 2021년 4월 28일
The attached minimum working example App might help you! Have a look.
  댓글 수: 2
Lee Xing Wei
Lee Xing Wei 2021년 4월 28일
It works! Thanks! How do you create this section? Is it startupFcn?
properties (Access = public)
t1 = 0;
dt = 1;
f1 = 10;
df = 5;
end
Subhadeep Koley
Subhadeep Koley 2021년 4월 28일
@Lee Xing Wei This is called Public Property. See this link to know more.

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

추가 답변 (1개)

Clayton Gotberg
Clayton Gotberg 2021년 4월 27일
I believe the reason it is overlapping each time is that your plot function only refers to y on each loop. When you only provide the axis argument and one other, it assumes you want them plotted from 1:size(input), so repeated calls would all start at the beginning. Try:
plot(app.UIAxes,x,y);
instead of
plot(app.UIAxes,y);
  댓글 수: 2
Lee Xing Wei
Lee Xing Wei 2021년 4월 28일
Your answer solve my other problem lol thx! But in this problem is the t1, how do I set the t1 as 0 before I push the button first time, and after I push the button the t1 become 1, second time become 2, so I can get a graph that connected by different time.
Clayton Gotberg
Clayton Gotberg 2021년 4월 28일
For that one, you will need to use a startupFcn in your app. See the tutorial here about giving initial parameters and variables to your app.

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

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by