How can I get a numeric vector of time from two string vectors containing date and time?

조회 수: 5 (최근 30일)
I have data from Keysight benchvue and I tried first to export it to Matlab format but then the timestamp vector has values like
>> format long
>> Time_s(1)
ans =
1.312396739146183e+17
which is far from what I would expect. This data was taken at 2016-11-18 19:29:51:461 and converting that to a numeric gives
>> datenum(2016,11,18,19,29,51.461)
ans =
7.366528124011690e+05
I then tried to export it to csv-format instead and reading it with textscan. In that case I get two cell arrays, one containing the date and one containing the time. I don't understand how to use datevec to get the time as a numeric vector. I have tried
>> datevec(theContent{1} theContent{2})
datevec(theContent{1} theContent{2})
Error: Unexpected MATLAB expression.
where
>> theContent{1}(1)
ans =
'2016-11-18'
and
>> theContent{2}(1)
ans =
'19:29:51.461'
I also tried to concatenate the two arrays but then I get no blank space between them
>> strcat(theContent{1}(1),theContent{2}(1))
ans =
'2016-11-1819:29:51.461'
I guess (and hope) that this has a simple solution that some of You knows about.
Any suggestions are highly appreciated!
Thanks in advance!
Emanuel
  댓글 수: 4
Walter Roberson
Walter Roberson 2016년 11월 21일
This shows that the timestamps you are seeing are potentially in IEEE-1588 format. Unfortunately in the time I spent investigating, I did not figure out what the format is, exactly. No obvious conversion suggested itself.
Emanuel Gunnarsson
Emanuel Gunnarsson 2016년 11월 21일
편집: Emanuel Gunnarsson 2016년 11월 22일
Hi again Walter! Thanks for spending time on it! I accually saw the post You linked to yesterday, but as You say: one does not get any wiser from that.

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

채택된 답변

Preethi
Preethi 2016년 11월 21일
hi,
use datenum and datevec
>> datevec(7.366528124011690e+05)
ans =
2016 11 18 19 29 51.461
>> datetime(ans)
ans =
18-Nov-2016 19:29:51
hope this is useful.
  댓글 수: 3
Preethi
Preethi 2016년 11월 21일
편집: Preethi 2016년 11월 21일
try
x = sprintf([theContent{1}(1),' ' ,theContent{2}(1)])
Emanuel Gunnarsson
Emanuel Gunnarsson 2016년 11월 21일
Hi again Preethi!
Yeah!! Thank You so much!
Apart from that the paranthesis should be changed to curly brakcets, this really solved it for me! Now I can do what You suggested:
>> x = sprintf([theContent{1}{1},' ' ,theContent{2}{1}])
x =
2016-11-18 19:29:51.461
>> datevec(x)
ans =
2016 11 18 19 29 51.4610000000102
Great!

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

추가 답변 (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