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 Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by