フィルターのクリア

Get proper time in seconds at x-axis from timestamps

5 ビュー (過去 30 日間)
Maximilian
Maximilian 2023 年 3 月 2 日
コメント済み: Peter Perkins 2023 年 3 月 13 日
Hey, I'm a new matlab user and hope you can help me with this problem.
I have numerous files. When I plot the data as I want it, I get the sample number on the x-axis (image 1). But instead I would like to get the time development in seconds. Starting with 0 seconds on the x-axis (first file) and then the course of time of these files.
I tried to extract the time from the file (example: (H:MI:S) = (16-39-44)) but it didnt work out.
When I plot it at the moment it looks like this (image 2) and gives me the sample number in x-axis.
Hope you can help. Thanks a lot in advance for recommendations!

採用された回答

Cameron
Cameron 2023 年 3 月 2 日
編集済み: Cameron 2023 年 3 月 2 日
%fileNames is the list of your files and t is a duration array in minutes
%without the milliseconds as you indicated earlier
fileNames = ["Baseline_Transmission__0__16-39-44-652.txt";
"Mineral Base_Transmission__0__16-40-21-553.txt";
"Mineral Licht_Transmission__0__16-40-42-818.txt";
"Mineral Licht_Transmission__10__16-41-06-585.txt"];
NumOnly = regexp(fileNames,'\d*','Match');
for r = 1:length(NumOnly)
n = str2double(NumOnly{r});
timeArray(r,1) = strjoin([n(2),":",n(3),":",n(4)],'');
end
dt = datevec(datetime(timeArray,'InputFormat',"HH:mm:ss"));
t = duration(dt(:,4:end));
To keep the milliseconds, you could use this (thanks to @Star Strider):
for r = 1:length(NumOnly)
n = str2double(NumOnly{r});
timeArray(r,1) = strjoin([n(2),":",n(3),":",n(4),'.',n(5),],'');
end
t = datetime(timeArray,'InputFormat',"HH:mm:ss.SSS",'Format','HH:mm:ss.SSS');
  2 件のコメント
Maximilian
Maximilian 2023 年 3 月 3 日
This helped a lot! Thank you.
Peter Perkins
Peter Perkins 2023 年 3 月 13 日
If you want to end up with durations from text, there is probably no need to create datetimes as an intermediate step:
duration("12:34:56")
ans = duration
12:34:56
duration("12:34:56.789",Format="hh:mm:ss.SSS")
ans = duration
12:34:56.789
In any case, don't use datevec+duration to get durations from a datetime, just use timeofday:
timeofday(datetime("now"))
ans = duration
21:39:59

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultirate Signal Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by