필터 지우기
필터 지우기

using datenum over several years

조회 수: 4 (최근 30일)
Richard
Richard 2012년 3월 22일
Say if I want to find the decimal day of year I would use:
clear all
StartDate = '2011-01-01 00:00';
EndDate = '2011-12-31 23:57';
Resolution = 60;
DateTime=datestr(datenum(StartDate,'yyyy-mm-dd HH:MM'):Resolution/(60*24):...
datenum(EndDate,'yyyy-mm-dd HH:MM'),...
'yyyy-mm-dd HH:MM');
DateTime=cellstr(DateTime);
JDay = cellfun(@(x)datenum(x),DateTime,'un',0);
DecDay = cell2mat(cellfun(@(x)x - datenum(2011,0,0),JDay,'un',0));
How is this achieved if the data extends over one year? So, say that my start data remains the same but my end data changes to '2013-12-31 23:57' how would I convert my time series into decimal day of year.
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 22일
Note that datenum(2011,0,0) is not '2011-01-01 00:00' but:
datestr(datenum(2011,0,0),'dd-mmm-yyyy HH:MM:SS PM')
ans =
31-Dec-2010 12:00:00 AM

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

채택된 답변

Oleg Komarov
Oleg Komarov 2012년 3월 22일
InDate = '2011-01-01 00:00';
FiDate = '2021-01-31 23:57';
% Create hourly spaced datetimes
v = datenum(InDate):1/24:datenum(FiDate);
% Shift with respect to InDate
v - datenum(InDate)
If you need to start from 1 just add '+ 1' to the last statement

추가 답변 (0개)

카테고리

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