MATLAB Answers

How to change X axis in the form of percentage

3 views (last 30 days)
preeti verma
preeti verma on 8 May 2021
Commented: Star Strider on 8 May 2021
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

Answers (2)

Star Strider
Star Strider on 8 May 2021
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 Comments
Star Strider
Star Strider on 8 May 2021
@Steven Lord — Thank you! I’ve used normalize (introduced in R2018a), however I didn’t think of using it here.

Sign in to comment.


VBBV
VBBV on 8 May 2021
%f true
x = 77:146;
xp = (x./max(x))*100
plot(xp,yp)% yp is your initial y values
  5 Comments
Dyuman Joshi
Dyuman Joshi on 8 May 2021
You are correct regarding the fact that normalizing is relative to the requirement. Also, I think you should edit your
answer, so that it is according to the question.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by