How to make the axis adjust to new plots

조회 수: 1 (최근 30일)
Anon
Anon 2020년 12월 20일
답변: Cris LaPierre 2020년 12월 24일
In the app designer i have included a plot for projectile motion, however i cant seem to make the axis values adjust when plotting a second graph on top of it- it remains at the limits of the first plot i.e. i cant see the second plot provided the x and y values are greater than the first plot
any help would be greatly appreciated! im pulling my hair out over this!
comet(app.Graph,x,y,0.1)
hold(app.Graph,'on')
  댓글 수: 4
Jan
Jan 2020년 12월 20일
Please post code as text, noit as screenshot. This makes it much easier to use copy&paste to post an answer.
Anon
Anon 2020년 12월 20일
t = linspace(0,tFinal,100) %creates an array of time with 100 elements
x = v0x.*t %calculates the range (x)
y = y0 + v0y.*t+0.5*g*t.^2 %calculates the height (y)
y(y < 0) = 0; %the y-axis cannot go below 0!
comet(app.Graph,x,y,0.1) %plots the projectile as a comet animation
hold(app.Graph,'on')
plot(app.Graph,x(y==max(y)),y(y==max(y)),'ro')
text(app.Graph,x(y==max(y)),y(y==max(y)),'\leftarrow MAX HEIGHT')
sorry about that - first time posting a question!

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

답변 (2개)

Cris LaPierre
Cris LaPierre 2020년 12월 24일
I would add the following to the bottom of your plotting code.
hold(app.Graph,'off') % best practice to always pair hold on with a hold off
axis(app.Graph,'auto')

Rishabh Mishra
Rishabh Mishra 2020년 12월 24일
Hi,
Based on my understanding of the issue, I can assume that you are using ‘app.graph’ as axes handle object to create plots over it.
In this case, since the x & y limits of the axes object is not appropriate, you are unable to view the 2nd plot.
To resolve the issue, readjust the x & y limits of the axes handle object ‘app.graph’. The code is given below:
app.graph.XLim = [-20 20]; % example range of values
app.graph.YLim = [-20 20]; % example range
The range of values above should be such that it includes both the plots.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by