필터 지우기
필터 지우기

convert day year hour data series with missing data to a serial number

조회 수: 1 (최근 30일)
I have a year of data from "01/01/2003 00:00" to "2003/12/31 23:59" with some days/hous missing from the data series. I think to convert these dates/times to serial numbers I have to use the datenum. To convert each one of these numbers I understand that I have to do: datenum(2003,1,1,0,0,0) which gives ans =
731582.00
This is fine for one number but how I can convert the whole series? thanks, Katerina

채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 8월 26일
편집: Andrei Bobrov 2014년 8월 26일
f = fopen('dates1.txt');
c = textscan(f,'%s %s','collectoutput',1);
fclose(f);
out = datenum(strcat(c{1}(:,1),{'_'},c{1}(:,2)),'dd/mm/yyyy_HH:MM');
or
f = fopen('dates1.txt');
c = textscan(f,'%s','delimiter','\n');
fclose(f);
out = datenum(c{1},'dd/mm/yyyy HH:MM')
  댓글 수: 4
Andrei Bobrov
Andrei Bobrov 2014년 8월 27일
Let your year: year1 = 2014
dt = datenum([2014 1 1 0 0 0;2014 12 31 23 0 0]);
out = (dt(1):1/24:dt(2))';

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

추가 답변 (1개)

Adam
Adam 2014년 8월 22일
str{1} = '01/01/2003 00:00'
str{2} = '2003/12/31 23:59'
datenum( str )
ans =
1.0e+05 *
7.3158
7.3195
So you should just be able to put all your strings into a cell array and pass that in to datenum
  댓글 수: 5
Katerina F
Katerina F 2014년 8월 25일
It is one column of data. Each line in the column is for example: 31/01/2003 16:00
Adam
Adam 2014년 8월 26일
편집: Adam 2014년 8월 26일
If it is a cell array you should just be able to pass it to datenum. If not then you will need to convert each row to a cell containing the string rather than a standard char matrix using e.g.
dateCells = cellstr( dates )

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

카테고리

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