how to put year as date tick in matlab
2 views (last 30 days)
Show older comments
hi, i am trying to put date tick in x axis using MATLAB 2010, date range is 2011/2012, but i have error in year format in x axis, the code is below thanks to help me
set(figure,'Color','white')
startDate = datenum(txt(w+2));
endDate = datenum(txt(end));
xData = linspace(startDate,endDate,length(de));
str = datestr(xData, 'mmm-yyyy');
plot(xData,de,'b',xData,re,'k')
NumTicks = 12;[enter image description here][1]
L = get(gca,'XLim');
set(gca,'XTick',linspace(L(1),L(2),NumTicks))
datetick('x','mmm yyyy','keeplimits', 'keepticks')
xticklabel_rotate;
set(gca,'XMinorTick','on','YMinorTick','on')
y_labels = get(gca, 'YTick');
set(gca, 'YTickLabel', y_labels); [year format error][1]
5 Comments
dpb
on 16 Feb 2016
There is no variable re in the above code snippet and the numbers pasted above seem to have no bearing on what the date string format is which is the issue if the date returned by datestr didn't match.
This is a two way street, we can't see your terminal from here so you've got to give sufficient detail and pertinent information to have any chance that somebody can solve the problem.
But, the general advice is, fix the call to datenum to include a date format string that matches what the input dates look like. When you've done that, check that the above test indicates you got it right.
doc datenum % see formatIn argument for details
Accepted Answer
Walter Roberson
on 16 Feb 2016
Change
startDate = datenum(txt(w+2));
endDate = datenum(txt(end));
to
startDate = datenum(txt(w+2), 'dd/mm/yyyy');
endDate = datenum(txt(end), 'dd/mm/yyyy');
More Answers (0)
See Also
Categories
Find more on Dates and Time 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!