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!