필터 지우기
필터 지우기

Convert seconds to HH:MM:SS.FF

조회 수: 29 (최근 30일)
Yu
Yu 2021년 8월 27일
댓글: Yu 2021년 8월 27일
I have time stamps that have hh:mm:ss and nanoseconds in different columns and want to convert them to hh:mm:ss.ff.
I did as following but have no idea what to do next.
Any ideas on how can I do this?
Thanks.
clear
load sample.mat
sample.SECONDS = datenum(sample.TIME)+sample.NANOSECONDS*10^(-9);

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 27일
sample.SECONDS = datenum(sample.TIME) + seconds(sample.NANOSECONDS*10^(-9));
sample.SECONDS.Format = 'hh:mm:ss.ff';
The second step will be rejected because datetime() objects have no 'ff' format specification. (And be careful, since for datetime() object, 'hh' is hour in 12 hour notation)
Perhaps you want to use datenum objects. However, datenum objects do not have a 'ff' specification either: they have a 'FF' specification.
I recommend
sample.SECONDS.Format = 'HH:mm:ss.SS';
  댓글 수: 3
Walter Roberson
Walter Roberson 2021년 8월 27일
sample.SECONDS = sample.TIME + seconds(sample.NANOSECONDS*10^(-9));
sample.SECONDS.Format = 'HH:mm:ss.SS';
Yu
Yu 2021년 8월 27일
This worked well!
Thank you so much! I really appreciate your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by