how to plot x= 0:0.01:10
53 views (last 30 days)
Show older comments
i attempted to do this but instead of giving me 0,1,2,3,4,5,6,7,8,9,10 on the x axis it gives me 0,5,15,20 idont understand why. Do i have to use linspace instead, on the newer version of matlab instead of what i used in the question?
0 Comments
Accepted Answer
Dyuman Joshi
on 10 Dec 2023
I'm not sure what are you plotting against, but you will have to specify xticks manually -
x = 0:0.01:10;
y = sin(x);
%Default plot
figure
plot(x, y)
%Modified xticks
figure
plot(x,y)
xticks(0:10)
0 Comments
More Answers (1)
Image Analyst
on 10 Dec 2023
Your badly-named "x" variable (almost everyone else would have called it y) goes from 0 to 10 in a thousand and one steps. When you plot just x, it will use x as the y value and the index (1 to 1001) as the x value.. Hence you will get a plot like this.
x = 0:0.01:10
plot(x, 'b.-', LineWidth=2);
grid on;
xlabel('Index');
ylabel('Value of x');
title('x = 0:0.01:10')
Note that the x axis plots indexes 1 - 1001, and the y axis plots the value of your badly-named data.
If you have some other y and you want your x to actually be x, then you can't just plot(x), you must plot(x, y). Then to set up your x tick mark labels you can use xticks
xticks(0 : 10);
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!