date and time serial conversion
조회 수: 8 (최근 30일)
이전 댓글 표시
I have a table with one million rows and 5 columns. The first column has the dates and the second column the time. I want toconvert the date and time to a number as i want to turn the table into a matrix and a matrix cannot have date and time.
댓글 수: 4
per isakson
2014년 11월 4일
"appear as 26072004"   Why do you want it that way? To me that is asking for problems down the road.
채택된 답변
per isakson
2014년 11월 4일
편집: per isakson
2014년 11월 5일
Hint:
>> sdn = datenum('04.11.2014','dd.mm.yyyy' )
sdn =
735907
Matlabs serial date number and
>> [60,1]*sscanf( '12:48', '%2d:%2d')
ans =
768
minutes after midnight
A nice thing about this is that you get integers (flint) and do not need to worry about precision when you do comparisons.
 
Some code added
fid = fopen('AA.txt');
cac = textscan( fid, '%s%s%f' );
fclose(fid)
[60,1]*sscanf( transpose(char(cac{2})),'%2d:%2d', [2,inf] )
returns
ans =
767 768 769
where   AA.txt   contains
04.11.2014 12:47 1
04.11.2014 12:48 2
04.11.2014 12:49 3
댓글 수: 2
per isakson
2014년 11월 4일
편집: per isakson
2014년 11월 4일
"the table"   what do you mean by table? Do you mean a text-file?
"x"   what is x?
추가 답변 (1개)
Michael Haderlein
2014년 11월 4일
You can use datenum:
datevec(datenum('04.11.2014 12:48','dd.mm.yyyy HH:MM'))
ans =
2014 11 4 12 48 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!