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 次查看(过去 30 天)
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?

采纳的回答

Akira Agata
Akira Agata 2018-3-30
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 个评论
Thomas Gunther
Thomas Gunther 2018-3-30
Sorry, I couldn't put in all the required information in my description. The Time Stamp column only represents a sampling rate. I am currently using a 1 second sampling rate, so TS's will be one second apart and no dates in this data.
Akira Agata
Akira Agata 2018-3-30
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);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by