how to set the limit of x axis and y axis as per the required range for the following code

29 Ansichten (letzte 30 Tage)
code:
x=1:12
y=[11 3 9 6 6 8 8 10 9 8 10 11];
xlim([0,12]);
ylim([0,12]);
plot(x,y,'-k*')
when i run the code i am getting the graph but the x axis values and y axis values are not in the required range.Could anyone please help me on this.
  2 Kommentare
Mathieu NOE
Mathieu NOE am 8 Jan. 2021
hello
you have to put the plot command first otherwise the xlim and ylim have no object to work on
plot(x,y,'-k*')
xlim([0,12]);
ylim([0,12]);
Rik
Rik am 2 Mär. 2021
There is a nuance here: xlim and ylim need an existing axes object and will not create one. That means you have to make sure an axes object exists, which you can do with plot, but also with many other functions. The order you proposed in your answer (which you posted as comment) makes the most sense, as plot will (under some conditions) modify the limits.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

jaah navi
jaah navi am 8 Jan. 2021
Thanks for your info.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by