how to plot x= 0:0.01:10
19 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Dyuman Joshi
2023-12-10
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 个评论
更多回答(1 个)
Image Analyst
2023-12-10
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!