How to convert time stamp 11:21:17.155 into seconds in MATLAB??

조회 수: 3 (최근 30일)
Suvvi Kuppur Narayana Swamy
Suvvi Kuppur Narayana Swamy 2021년 1월 19일
댓글: Stephen23 2021년 1월 19일
I am quite not sure how to covert time stamps of this sort into seconds in MATLAB. Any help is appreciated.
Thank you
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 1월 19일
hello
try this :
a = '11:21:17.155';
n = split(a,':');
duration_seconds = str2num(n{1})*3600+str2num(n{2})*60+str2num(n{3})
Stephen23
Stephen23 2021년 1월 19일
a = '11:21:17.155';
b = [60*60,60,1]*str2double(split(a,':'))
b =
40877.155

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

채택된 답변

Stephan
Stephan 2021년 1월 19일
format longG
a = '11:21:17.155';
b = seconds(duration(a,'InputFormat','hh:mm:ss.SSS'))
results in:
b =
40877.155

추가 답변 (1개)

Stephen23
Stephen23 2021년 1월 19일
The most efficient solution:
a = '11:21:17.155';
b = [60*60,60,1]*sscanf(a,'%f:')
b =
40877.155

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by