how to plot x= 0:0.01:10
17 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Dyuman Joshi
il 10 Dic 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 Commenti
Più risposte (1)
Image Analyst
il 10 Dic 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 Commenti
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!