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

James Tursa
James Tursa 2014년 11월 4일
How is the data stored? Cell array of strings or what? What number do you want the date converted to? Datenum or Julian Day or what?
AA
AA 2014년 11월 4일
the data is stored in table format (so not matrix or cell array but table format). I want to convert it to a matrix. The date is given as '26.07.2004' in column 1 and the time is given as '2:00' in column 2. I want the date to appear as 26072004 and the time as 0200. Then I can convert this table into a matrix.
per isakson
per isakson 2014년 11월 4일
"appear as 26072004" &nbsp Why do you want it that way? To me that is asking for problems down the road.
AA
AA 2014년 11월 4일
you are right. datenum format is better. How do I change it into datenum format?

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

 채택된 답변

per isakson
per isakson 2014년 11월 4일
편집: per isakson 2014년 11월 5일

1 개 추천

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.
&nbsp
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 &nbsp AA.txt &nbsp contains
04.11.2014 12:47 1
04.11.2014 12:48 2
04.11.2014 12:49 3

댓글 수: 2

AA
AA 2014년 11월 4일
how can i incorporate the table into the time command. x variable is the the column that has the values for time and i get the following error:
b=[60,1]*sscanf(x, '%2d:%2d') Error using sscanf First argument must be a string.
per isakson
per isakson 2014년 11월 4일
편집: per isakson 2014년 11월 4일
"the table" &nbsp what do you mean by table? Do you mean a text-file?
"x" &nbsp what is x?

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

추가 답변 (1개)

Michael Haderlein
Michael Haderlein 2014년 11월 4일

0 개 추천

You can use datenum:
datevec(datenum('04.11.2014 12:48','dd.mm.yyyy HH:MM'))
ans =
2014 11 4 12 48 0

댓글 수: 1

AA
AA 2014년 11월 4일
I want the date to be converted to one integer and stay in the same column and row. the table variable is called x

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

카테고리

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

질문:

AA
2014년 11월 4일

편집:

2014년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by