Customizing the tick values and labels along x axis

조회 수: 26 (최근 30일)
Susan
Susan 2021년 6월 23일
댓글: Star Strider 2021년 6월 23일
Hi All,
When I plot(1:20, f), the x-axis are shown from 1 to 20. However my real x values are
x =
Columns 1 through 13
30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000
Columns 14 through 20
4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000
and I'd like the real x values to show up in the figure. To do so, I used
xticks([x])
and got an error that says
Value must be a numeric vector whose values increase.
Any idea how I can fix this issue?
Thanks in advance

채택된 답변

Star Strider
Star Strider 2021년 6월 23일
편집: Star Strider 2021년 6월 23일
Try something like this:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(rand(1,20))
set(gca, 'XTick',1:20, 'XTickLabel',compose('%g',x))
EDIT — (23 Jun 2021 at 22:21)
Since I’m not certain what you’re actually doing, another option is:
x = [30.0000 28.0000 26.0000 24.0000 22.0000 20.0000 18.0000 16.0000 14.0000 12.0000 10.0000 8.0000 6.0000 4.0000 2.0000 1.0000 0.8000 0.6000 0.4000 0.2000];
figure
plot(x, rand(1,20))
set(gca, 'XTick',sort(x), 'XDir','reverse')
.
  댓글 수: 2
Susan
Susan 2021년 6월 23일
Thank you so much, @Star Strider!
Star Strider
Star Strider 2021년 6월 23일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by