Create a time array
조회 수: 148 (최근 30일)
이전 댓글 표시
Hey guys, thanks in advance.
I have one matrix of data( this is a char data) that has two times : as visible in this figure
'Canal zero_timestamp.mat'
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1051615/image.png)
those numbers are: hour-minutes-seconds-miliseconds
I need to produce a time array with duration in seconds between first element of this matrix and the last element(17-11-09_923).
I wanted to conserve the miliseconds, is there anyway?
댓글 수: 0
채택된 답변
Steven Lord
2022년 6월 30일
val=['17-10-58_086'
'17-11-09_923'];
val = string(val);
Convert the string array val into a format the duration function knows how to import.
val = replace(val, '-', ':');
val = replace(val, '_', '.');
d = duration(val)
The fractional seconds are present, they're just not displayed with the default display Format. We can change the Format to show them.
d.Format = 'hh:mm:ss.SSS'
Now compute the difference in seconds.
seconds(diff(d))
댓글 수: 0
추가 답변 (2개)
Fangjun Jiang
2022년 6월 30일
편집: Fangjun Jiang
2022년 6월 30일
val=['17-10-58_086'
'17-11-09_923']
StartEnd=datetime(val,'InputFormat','HH-mm-ss_SSS')
TimeVector=StartEnd(1):seconds(1):StartEnd(2)
datestr(TimeVector,'HH-MM-SS_FFF')
댓글 수: 0
Voss
2022년 6월 30일
val = [ ...
'17-10-58_086'; ...
'17-11-09_923'; ...
]
dt = datetime(val,'InputFormat','HH-mm-ss_SSS')
dt_diff = dt(end)-dt(1)
% the milliseconds are present in dt_diff:
seconds(dt_diff)
milliseconds(dt_diff)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!