How do I add monthly labels to my time series plot?
6 views (last 30 days)
Show older comments
I have data points between 1 and 9862, respresenting each day from 1990 to 2017. I have extracted the first 5 years of data and want to add monthly labels on the x-axis e.g. Oct1990 Nov1990 ..... Sep1995.
dpb on 25 Jan 2023
Ah! Typos are the bane of programming! :)
t=datetime(1990,1,1):datetime(2016,12,31); % datetime vector
is5=isbetween(t,t(1),t(1)+years(5)); % logical to get 5 years from beginning
plot(t(is5),randn(sum(is5),1)) % use your dependent variable indexed, too, of course
There's not enough space to label monthly unless you compress the formatting string and/or rotate the labels, but you get time labels automagically with the datetime axis.
Find more on Characters and Strings 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!