1 have 3 csv files of various sizes with timestamps (TS) in Column 1 of each csv. 2 csv files will always have same size matrix, but third csv TS is delayed which causes a smaller matrix. How do I pad third csv with 0's until TS3 = TS1 or TS2?
2 views (last 30 days)
Show older comments
Thomas Gunther
on 29 Mar 2018
Commented: Akira Agata
on 30 Mar 2018
1 have 3 csv files of various sizes with timestamps (TS) in Column 1 of each csv. 2 csv files will always have same size matrix, but third csv TS is delayed which causes a smaller matrix. How do I pad third csv with 0's until TS3 = TS1 or TS2?
0 Comments
Accepted Answer
Akira Agata
on 30 Mar 2018
Assuming your data in 3 csv files are stored in timetable, say TT1 TT2 and TT3, you can pad the data in TT3 with 0s until TT3's timestamp is TT1's timestamp by using retime function, like:
% Sample data
TS = datetime({'2015-12-18 07:02:12';'2015-12-18 08:00:47';...
'2015-12-18 09:01:37';'2015-12-18 10:03:10';...
'2015-12-18 10:59:34'});
Data = [37.3;41.9;45.7;42.3;39.8];
TT1 = timetable(TS,Data);
TT3 = TT1(3:end,:);
% Pad a 3rd data with 0 until TT3.TS = TT1.TS
TT3 = retime(TT3,TT1.TS,'fillwithconstant','Constant',0);
2 Comments
Akira Agata
on 30 Mar 2018
Same way can be applicable. Please try to use timetable with duration vector as a time tamp. The following is an example.
% Sample data
TS = seconds(1:5)';
Data = [37.3;41.9;45.7;42.3;39.8];
TT1 = timetable(TS,Data);
TT3 = TT1(3:end,:);
% Pad a 3rd data with 0 until TT3.TS = TT1.TS
TT3 = retime(TT3,TT1.TS,'fillwithconstant','Constant',0);
More Answers (0)
See Also
Categories
Find more on Calendar in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!