Creat time series with real calendar

Hello all, I have a set of daily data that ranges from the years 1/Jan/1980 to 31/Oct/2100. The data is currently in vector. Each month has 30days so total value is 43140 values. Now i want to set the time series with real calendar. For example: January with 31 days so will copy last value, February has 28 days (no leap day) so will cut 2 days, March has 30 days will keep it and so on. Does anyone know how I can do this? I also have major problem solving all the leap day. Thank you for any comments or suggestions .

Respuestas (1)

Kelly Kearney
Kelly Kearney el 24 de Jun. de 2014
Are you sure you have data for every day in that range, assuming 30-day months? By my calculation, that would be 1450 months, or 43500 days, while you only seem to have 1438 months worth... seems to be a year short. Anyway, to create the new dataset:
day1 = '1-Jan-1980';
day2 = '31-Oct-2100';
% Yur dataset dates
yr = 1980:2100;
mn = 1:12;
dy = 1:30;
[dy,mn,yr] = ndgrid(dy,mn,yr);
dv = [yr(:) mn(:) dy(:) zeros(numel(yr),3)];
dv(datenum(dv)>datenum(day2),:) = [];
% Your vector data
x = rand(size(dv,1),1);
% Real dates
t = datevec(datenum(day1):datenum(day2));
% Figure out where they match, and fill in data
[tf,loc] = ismember(dv, t, 'rows');
xnew = nan(size(t,1),1);
xnew(loc(tf)) = x(tf);
idx = find(isnan(xnew));
xnew(idx) = xnew(idx-1);

1 comentario

Phuong Nam Vu
Phuong Nam Vu el 24 de Jun. de 2014
Thanks Kelly so much. Yes that is my needing. I am sorry for my wrong : Endyear is 31-Oct-2099, is not 2100. Again, Thanks so much.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 24 de Jun. de 2014

Comentada:

el 24 de Jun. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by