How to change X axis in the form of percentage

22 次查看(过去 30 天)
In this plot i want my x axis in the form of percentage value where it's range start with [77,146], 77 as 0 and 146 as 100%, without changing curve's y axis

回答(1 个)

Star Strider
Star Strider 2021-5-8
Try something like this —
x = linspace(77, 146);
y = -60 - 15*sin(2*pi*x/50);
figure
plot(x, y)
Ax = gca;
xt = Ax.XTick;
xtnew = (xt - min(xt))/(max(xt)-min(xt)) * 100;
Ax.XTickLabel = xtnew;
.
  2 个评论
Steven Lord
Steven Lord 2021-5-8
I'd use normalize rather than performing the calculations myself.
x = linspace(77, 146);
y = -60 - 15*sin(2*pi*x/50);
figure
plot(x, y)
xt = xticks;
normalizedX = normalize(xt, 'range', [0 100]);
xticklabels(normalizedX)
Star Strider
Star Strider 2021-5-8
@Steven Lord — Thank you! I’ve used normalize (introduced in R2018a), however I didn’t think of using it here.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by