Help with plot axis

13 visualizzazioni (ultimi 30 giorni)
Sinead Mc Kinney
Sinead Mc Kinney il 7 Mar 2017
Commentato: Star Strider il 7 Mar 2017
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.

Risposta accettata

Star Strider
Star Strider il 7 Mar 2017
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 Commenti
Sinead Mc Kinney
Sinead Mc Kinney il 7 Mar 2017
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 il 7 Mar 2017
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by