Read in dates (for timestamp) from file names
Show older comments
I am trying to read in data and the measurement timestamps do not include the dates. The filenames include the date/time when the file was started. How can save the date from the filename to use it in the timestamps for each measurement?
I was previously doing this:
filepath = 'HR3_181920/PH/';
filelist = dir(strcat(filepath,'*.txt'));
file_timestamps =cell2mat({filelist.datenum});
But this doesn't work because it is taking the date from the structure for the datenum value which I think is actually the time when the file ends (not the beginning). I have attached a file of the resulting structure which includes the names of the files I am trying to work with.
These are the 'file_timestamps' that I currently get when I run those line. Notice they match the date column but not the information in the name of the file.
2018 7 18 12 49 50
2018 7 18 12 54 48
2018 7 18 17 3 58
2018 7 19 0 0 2
2018 7 19 11 50 12
2018 7 19 11 54 18
2018 7 19 18 5 4
2018 7 19 18 25 20
2018 7 19 19 50 54
2018 7 19 20 26 12
2018 7 19 20 26 36
2018 7 19 20 27 20
2018 7 19 20 28 6
2018 7 19 20 28 54
2018 7 19 20 29 58
2018 7 19 20 32 28
Accepted Answer
More Answers (1)
Walter Roberson
on 26 Mar 2019
file_timestamps = datetime( regexp({filelist.name}, '^[^_]*', 'match', 'once'), 'InputFormat', 'yyyyMMMdd');
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!