How to include different values for x-ticks
Afficher commentaires plus anciens
Hi,
Suppose the following for X and Y, where x and y are some parameters measured from year 2000-2004.
x=[2 5 3 7 10]
y=[10 13 15 7 3]
On the figure I make, I want to put years (2000, ...,2004) rather than 1,....,5. How can I do that?
Thanks,
Thishan
Réponses (2)
Star Strider
le 15 Nov 2018
Try this:
x=[2 5 3 7 10];
y=[10 13 15 7 3];
yrs = 2000:2004;
t = datenum([yrs' zeros(numel(yrs),4) ones(size(yrs'))]);
figure
plot(t, x, t, y)
datetick('x', 'yyyy', 'keeplimits')
That will plot the years correctly.
2 commentaires
madhan ravi
le 15 Nov 2018
+1 always a saviour!
Star Strider
le 15 Nov 2018
@Madhan — Thank you!
madhan ravi
le 15 Nov 2018
Modifié(e) : madhan ravi
le 15 Nov 2018
x=[2 5 3 7 10];
y=[10 13 15 7 3];
plot(x,y)
xticks(linspace(x(1),x(end),4)) %likewise for y-axis
xticklabels({'2001','2002','2003','2004'})
4 commentaires
Thishan Dharshana Karandana Gamalathge
le 15 Nov 2018
Thishan Dharshana Karandana Gamalathge
le 15 Nov 2018
madhan ravi
le 15 Nov 2018
my suggestion is to upgrade to 2016b which makes your work a lot more easier and faster
Thishan Dharshana Karandana Gamalathge
le 15 Nov 2018
Catégories
En savoir plus sur Axis Labels dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!