Convert UNIX NanoSeconds to DTG in Milliseconds

조회 수: 8 (최근 30일)
Timothy
Timothy 2023년 8월 18일
답변: dpb 2023년 8월 19일
Hello,
I have to do 2 things: convert UNIX nanoseconds to DTG Nanoseconds, and then convert DTG Nanoseconds to DTG Milliseconds. The second conversion would be a "SUM" of all the entries into one millisecond. So for every nanosecond entry within millisecond "1," I would like to sum the different parts of the table and add them together to create a millisecond register instead of a nanosecond register. Does this make sense? Any questions are welcomed in order to reach this goal!
Thanks,
Tim
  댓글 수: 8
Timothy
Timothy 2023년 8월 19일
Now that I have it in Date-Time with nanoseconds, any ideas how to simply round it off to milliseconds?
Walter Roberson
Walter Roberson 2023년 8월 19일
If you had the time in int64 or uint64 nanoseconds, then to round to milliseconds, just divide them by 1000: operations on integer data classes automatically round
If you have double precision numbers, then see round which has the ability to indicate how many digits you want to round to.

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

답변 (1개)

dpb
dpb 2023년 8월 19일
Ah! That simplifies the problem immensely; you've already passed the hard part.
To do the initial request to sum over millisec time intervals, turn the data table into a timetable and use retime with the 'regular' sample rate and @sum method...
tt=timetable(yourdatetimevar,restofdata);
ttMS=retime(tt,'regular','sum','SampleRate',1000); % aggregate a msec sample rate
The above will start at the actual time in msec and aggreate within those groups; it will not resample to approximate at even msec times. If want that, use retime() and interpolate first, then aggregate. There may be a way to do both in one step, I'm not sure.

카테고리

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