Filter löschen
Filter löschen

Query about axes of graph created by plot function

2 Ansichten (letzte 30 Tage)
Erika Yoshikawa
Erika Yoshikawa am 9 Feb. 2021
Kommentiert: Star Strider am 10 Feb. 2021
If I have two variables A = [1 2 3] and B = [1 2 3], when I plot(A,B) I get a graph with 10 variables on both x and y axis with constant intervals between 1 and 3.
Is there a way where I can just get a graph with 3 values 1, 2 and 3 on both x and y axis?

Akzeptierte Antwort

Star Strider
Star Strider am 9 Feb. 2021
I am not certain what the original problem is with your plot.
Try this:
A = [1 2 3];
B = [1 2 3];
figure
plot(A, B)
Ax = gca;
Ax.XTick = A;
Ax.YTick = B;
.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 9 Feb. 2021
I suspect that you want to use xlim() and ylim()
  2 Kommentare
Erika Yoshikawa
Erika Yoshikawa am 9 Feb. 2021
Thank you for your answer. I think xlim() and ylim() limits the values on x and y axis, however it is not what I'm looking for.
When I enter the following:
A = [1 2 3]
B = [1 2 3]
plot(A,B)
I'm getting a graph which is shown in the screenshot:
I don't understand why matlab is changing the interval so there's 10 values on the x and y axes, but I just want 1, 2 and 3 on both x and y axis.
Walter Roberson
Walter Roberson am 9 Feb. 2021
MATLAB automatically chooses "nice" ticks. You can use xticks() and yticks() to choose different tick locations.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots 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