Append date to time column entries where time is sporadically placed throughout the table
2 次查看(过去 30 天)
显示 更早的评论
My data looks something like this:
time: service: user: otherdata:
09:00:00 @SERVICE first.last@machineName somedata
09:00:03 @SERVICE TIMESTAMP 12/31/2019
09:05:00 @SERVICE first.last@machineName somedata
09:08:00 @SERVICE first.last@machineName somedata
What I would like to do is append that 12/31/2019 to the time column, but the problem is that it's sporadically placed throughout the file. The main consistancy is the TIMESTAMP data that's in the user column, but I'm not exactly sure how to format the parsing to find it.
Any help would be greatly apprecaited.
2 个评论
Mohammad Sami
2020-1-3
If the format of the row with date is alway the same, you can use that to find the rows which contain date.
index = contains(stringdata,'@SERVICE TIMESTAMP');
rows_with_timestamp = stringdata(index);
% you can then parse using regexp textscan e.t.c
采纳的回答
Cris LaPierre
2020-1-3
Identifying a "best" solution will require some creativity and some knowledge of your data. Here's one simple approach that may get you started.
data = readtable('TylerRohren_data.txt')
ind = find(string(data.user_)=="TIMESTAMP",1,"first");
TS = datetime(data.otherdata_(ind));
for r = 1:height(data)
if string(data.user_(r))=="TIMESTAMP"
TS = datetime(data.otherdata_(r),'InputFormat',"MM/dd/uuuu");
end
time(r,1) = TS + data.time_(r);
end
data.time_ = time;
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!