I have a time series which my sensors recorded them in this format: 10.02.42.415 instead of this: 10:02:42.415 ! How can I fix my entire array (which is 465637 samples!)??
조회 수: 2 (최근 30일)
이전 댓글 표시
One of my sensors had an error during my data collection apparently and recorded the time series in a wrong format. I need to convert 10.02.42.415 to this: 10:02:42.415 in order to sync this time series with my other sensors. Thank you for your help
댓글 수: 0
채택된 답변
Cris LaPierre
2021년 6월 13일
The simplest way I can think of is to use datetime. Since you have no date associated with the time, sutract off today's date to leave time.
T = '10.02.42.415';
newT = datetime(T,'InputFormat','hh.mm.ss.SSS') - datetime('today');
newT.Format = 'hh:mm:ss.SSS'
댓글 수: 2
Cris LaPierre
2021년 6월 14일
It looks like you left some details out of your original post that make a difference. For example, you do have dates associated with your time.
My recommendation is to not use datenum. There are newer, better ways to represent dates and times in MATLAB. I would suggest using datetimes and durations for your first 3 columns, and a table to store it. It's a little more upfront work to get the import formatted correctly, but can be much easier to work with and avoid mistakes.
participant = "p1";
% there was no left wrist file, but there was a right
file_name= strcat(participant, '_right_wrist_accel.txt');
% set import settings
opts = detectImportOptions(file_name);
opts.VariableNames = ["epoch","timestamp","elapsed","X","Y","Z"];
opts = setvartype(opts,2,"datetime");
% Note that timezone is hardcoded. Your 2 files have different timezones
% If you do not need timezone, you can remove it
opts = setvaropts(opts,2,'InputFormat','yyyy-dd-MM''T''hh.mm.ss.SSS','TimeZone','-0500');
data = readtable(file_name,opts);
% convert epoch and elapsed to durations so that units can be tracked
data.epoch = milliseconds(data.epoch);
data.elapsed = seconds(data.elapsed);
data.timestamp.Format = "yyyy-dd-MM HH:mm:ss.SSS"
Your _lol_ file contains a different separator for time. Update the InputFormat to match (uses colons instead of periods).
추가 답변 (1개)
Khashayarash Abas
2021년 6월 14일
편집: Cris LaPierre
2021년 6월 14일
댓글 수: 1
John D'Errico
2021년 6월 15일
Please do not post an answer when you wanted to make a comment. Use comments instead.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!