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?

采纳的回答

Dyuman Joshi
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)

更多回答(1 个)

Image Analyst
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
x = 1×1001
0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600 0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300 0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000 0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700 0.2800 0.2900
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);

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by