Help with plot axis

조회 수: 13 (최근 30일)
Sinead Mc Kinney
Sinead Mc Kinney 2017년 3월 7일
댓글: Star Strider 2017년 3월 7일
I have a piece of code that goes through a loop 1000 times determining the values of x and y. I then plot these coordinates.
I want the x and y axis to be the same so I tried axis equal however I obtained a graph with the axises as so. Can anyone explain why the x and y axis aren't equal? The x axis ranges from -300 to 300 and the y axis from 0 to 450.

채택된 답변

Star Strider
Star Strider 2017년 3월 7일
The axis equal call uses the same length for the data units along each axis. It does not affect the range of values. If you want to change those, use the axis call as:
axis([xmin xmax ymin ymax])
You can also combine that call with an axis equal call, so one does not cancel or override the other.
  댓글 수: 2
Sinead Mc Kinney
Sinead Mc Kinney 2017년 3월 7일
Thanks for your response. However i'm not sure i am making use of this correctly. I want the x and y axis both to span the same range of values. See image attached - i would like the x axis to range from 0 to 450 as the y axis does. I have tried the following however i receive an error.
ymin = min(coords(:,2));
ymax = max(coords(:,2));
rangeOfyAxis=ymax-ymin;
xmin = -floor(rangeOfyAxis/2);
xmax = floor(rangeOfyAxis/2);
axis([xmin xmax,ymin ymax])
Error using matlab.graphics.axis.Axes/set Value must be a 1x2 vector of numeric type in which the second element is larger than the first and may be Inf
Error in axis>LocSetLimits (line 269) set(ax,...
Error in axis (line 98) LocSetLimits(ax(j),cur_arg,names);
Error in simulateLightningTenToThePowerOfThree (line 51) axis([xmin xmax,ymin ymax])
Star Strider
Star Strider 2017년 3월 7일
My pleasure.
‘I would like the x axis to range from 0 to 450 as the y axis does.’
Use the ‘ymin’ and ‘ymax’ values for both in your axis call:
axis([ymin ymax ymin ymax])
That should do what you want.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by