dateticks

13 次查看(过去 30 天)
Suame New Road
Suame New Road 2012-5-10
Please I have a two year water level data(2009-2010). The water level was taken every two days, meaninig that I have 365 observations which were plotted in days but the duration for the work was 730 days. I would like to use dateticks on the X-axis for the my Kalman Filter model. I would like the X-axis to read like this: jan-09 to dec-10. please how should I go about it. Thank you.
Atta-Darkwa

回答(1 个)

the cyclist
the cyclist 2012-5-10
Here is some code that will do what I think you want.
Monthly labels are very mashed on top of each other, so I did quarterly instead. But I left in the code (commented out) for monthly.
% Make up the days
d1 = datenum('jan-1-2009');
d2 = datenum('dec-31-2010');
dailyDates = d1:d2;
% Identify where the ticks are
% Use this instead for quarterly date ticks
dayVec = ones(1,8);
monthVec = [1,4,7,10,1,4,7,10];
yearVec = [2009*ones(1,4),2010*ones(1,4)];
tickLocations = datenum(yearVec,monthVec,dayVec);
% % Use this instead for monthly date ticks
% dayVec = ones(1,24);
% monthVec = [1:12,1:12];
% yearVec = [2009*ones(1,12),2010*ones(1,12)];
%
% tickLocations = datenum(yearVec,monthVec,dayVec);
% Make up the data
xvec = randn(1,numel(dailyDates));
% Plot the data (with specified tick labels)
figure
plot(dailyDates,xvec)
axis tight
set(gca,'XTick',tickLocations)
datetick('x','mmm-yy','keepticks','keeplimits')

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by