time stamps (string to number)

조회 수: 3 (최근 30일)
Tiina
Tiina 2011년 12월 15일
Hi guys,
How could I convert time stamps to a num or double, this is the format I have:
'09:35:00.000' '09:36:00.000' '09:37:00.000' '09:38:00.000' '09:39:00.000' '09:40:00.000' '09:41:00.000' '09:42:00.000'
I tried str2num str2double with various arguments... but got no where , I am assuming that the format of the time stamps is not read by those functions maybe, is there any function that am missing? Your help is appreciated.
  댓글 수: 2
Jan
Jan 2011년 12월 15일
It would be helpful if you define the wanted output. What do you want for '09:35:00.000' ?
Tiina
Tiina 2011년 12월 16일
Hi Jan,
You are right I should have been more detailed by expressing a format like 'hhmmss' for example ..

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 12월 15일
A = {'09:35:00.000' '09:36:00.000' '09:37:00.000' '09:38:00.000' '09:39:00.000' '09:40:00.000' '09:41:00.000' '09:42:00.000'};
out = datevec(A)
out = out(:,4:end)
  댓글 수: 1
Tiina
Tiina 2011년 12월 15일
Thanks Andrei

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

추가 답변 (1개)

Jan
Jan 2011년 12월 15일
A = {'09:35:00.000' '09:36:00.000' '09:37:00.000' '09:38:00.000' '09:39:00.000' '09:40:00.000' '09:41:00.000' '09:42:00.000'};
B = sprintf('%s:', A{:});
C = reshape(sscanf(B, '%g:'), 3, []);
Then you have:
C = [ 9 9 9 9 9 9 9 9
35 36 37 38 39 40 41 42
0 0 0 0 0 0 0 0];
If you want to convert it to seconds:
D = [3600, 60, 1] * C;

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by