sqaure of number xlabel

2 views (last 30 days)
vishal kaushik
vishal kaushik on 20 May 2020
Edited: dpb on 20 May 2020
I am using matlab 2019b
I am plotting two data one on x axis and one on y axis data
x=(25:25:625).^2
I want to plot on x axis 25^2 , 50^2 , 75^2.......625^2
But I dont know how to do that,Please some one can help me with this
I did tries with xtick but its not properly displaying.

Accepted Answer

Ameer Hamza
Ameer Hamza on 20 May 2020
Try something like this
x = (25:25:625).^2;
y = sqrt(x);
plot(x, y)
xticks(x)
xticklabels(compose('%d^2', 25:25:625))
  4 Comments
dpb
dpb on 20 May 2020
Edited: dpb on 20 May 2020
"does not ensure that the xticks always appear at an integer location"
Of course they'll be integer...auto-scaling axes of large numbers will never put a tick at a noninteger value and integers up to a very large number are exactly representable in a double.
But, I see when I cut and pasted from the command window I inadvertentedly deleted a wanted step so good catch on that...that step was:
xticks([x(1:5:end) x(end)].^2)
to pick the lesser number and to match the previously-set xlim values...fixed earlier comment to include.
Ameer Hamza
Ameer Hamza on 20 May 2020
Yes, this makes more sense now.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!