MATLAB: 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 to pad third csv with 0’s until TS3 = TS1 or TS2

MATLABmatrix manipulation

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?

Best Answer

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);