Query about axes of graph created by plot function

조회 수: 1 (최근 30일)
Erika Yoshikawa
Erika Yoshikawa 2021년 2월 9일
댓글: Star Strider 2021년 2월 10일
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?

채택된 답변

Star Strider
Star Strider 2021년 2월 9일
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;
.
  댓글 수: 2
Erika Yoshikawa
Erika Yoshikawa 2021년 2월 9일
That solved the problem, thank you!
Star Strider
Star Strider 2021년 2월 10일
My pleasure!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 9일
I suspect that you want to use xlim() and ylim()
  댓글 수: 2
Erika Yoshikawa
Erika Yoshikawa 2021년 2월 9일
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 2021년 2월 9일
MATLAB automatically chooses "nice" ticks. You can use xticks() and yticks() to choose different tick locations.

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

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by