how to multiply displayed xvalues on plot by constant

How can I change the the display, that is the way the x values look on the plot (not the x-values themselves in the code - just the way they look) to multiply them by a constant. Kind of like scaling.

 採用された回答

Jos (10584)
Jos (10584) 2018 年 1 月 31 日

5 投票

Here is one approach:
% create plot
x=-10:2:10
y = x.^2
plot(x,y,'bo-')
% modify labels for tick marks
xticks = get(gca,'xtick')
scaling = pi
newlabels = arrayfun(@(x) sprintf('%.1f', scaling * x), xticks, 'un', 0)
set(gca,'xticklabel',newlabels)

3 件のコメント

Omkar Banne
Omkar Banne 2019 年 5 月 18 日
Thanks a lot Jos (10584). It worked for me!
Maitrayee Ghosh
Maitrayee Ghosh 2020 年 8 月 17 日
This code shows some errors in the last line with delimiters.
Rik
Rik 2020 年 8 月 17 日
@Maitrayee Ghosh what exact code are you using and what is the complete error message?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2018 年 1 月 31 日

コメント済み:

Rik
2020 年 8 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by