MATLAB Answers

Modify axis tick frequency

104 views (last 30 days)
Dear Matlab community,
I have successfully produced the following plot:
by using the following code:
xlim([dn(1) dn(end)]);
I now would like to adjust the frequency of the x-axis date ticks, but I cannot make sense of the function. I believe datetick is set on auto mode, where it produces a default number of ticks. I am looking for 1-year and 5-year intervals.
Thank you very much! The help from the MATLAB community has helped me a great deal!

Accepted Answer

Walter Roberson
Walter Roberson on 12 Aug 2015
If you want 1 year and 5 year ticks both at the same time then you would be wanting the 1 year ticks to be Minor Ticks and the 5 year ticks to be the major ticks. See for information about setting minor ticks.
For the 5 year ticks:
tick5 = datenum(1930:5:2014,1,1);
set(gca, 'xtick', tick5);
datetick('x', 'yyyy', 'keepticks');
Ehsan Modiri
Ehsan Modiri on 27 Jun 2020
tick5 = datetime(1930:2014,1,1);
set(gca, 'Xtick', tick5)
instead of datenum, you can use datetime.

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!