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 .

답변 (1개)

Kelly Kearney
Kelly Kearney 2014년 6월 24일

1 개 추천

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

Phuong Nam Vu
Phuong Nam Vu 2014년 6월 24일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

질문:

2014년 6월 24일

댓글:

2014년 6월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by