MATLAB: Matching different time series

matrixmatrix arraytime series

Hi, I have several data (files) that each of them contains one column for time and some columns for values of some variables. I want to match these data according to time in one file but the start time, finish time and sample time (time interval) are given by user. Actually I want to have the values (if it is possible the real value or the closest approximation) of all variables at times that the user wants. For example, suppose that I have two data sets (A and B) as the following and the user wants to have the values of these variables based on the following start time, finish time and sample time (time interval): A=[‘29/07/2014 08:00:06.415’ 21 ‘29/07/2014 08:10:06.415’ 23 ‘29/07/2014 08:18:06.415’ 27] ; B=[‘29/07/2014 08:05:06.415’ 2.1 ‘29/07/2014 08:08:06.415’ 3.1 ‘29/07/2014 08:19:06.415’ 4.5]; Start time: ‘29/07/2014 08:00:00.000’; Finish time: ‘29/07/2014 08:20:00.000’; Sample time: 5 ;% based on minute
Finally I want to have a set of data as the following: F=[‘29/07/2014 08:00:00.000’ A1 B1 ‘29/07/2014 08:05:00.000’ A2 B2 ‘29/07/2014 08:10:00.000’ A3 B3 ‘29/07/2014 08:15:00.000’ A4 B4 ‘29/07/2014 08:20:00.000’ A5 B5]; That A1:A5 and B1:B5 are the closest approximation to the real ones that are mentioned in A and B (if there are different methods for approximation, please tell me). Please help me how can I do this work?

Best Answer

Please try is it:
A={'29/07/2014 08:00:06.415' 21
'29/07/2014 08:10:06.415' 23
'29/07/2014 08:18:06.415' 27} ;
B={'29/07/2014 08:05:06.415' 2.1
'29/07/2014 08:08:06.415' 3.1
'29/07/2014 08:19:06.415' 4.5};
xa = datenum(A(:,1),'dd/mm/yyyy HH:MM:SS.FFF');
xb = datenum(B(:,1),'dd/mm/yyyy HH:MM:SS.FFF');
fa = griddedInterpolant(xa,cell2mat(A(:,2)));
fb = griddedInterpolant(xb,cell2mat(B(:,2)));
xx = datenum(2014,7,29,8,(0:5:20)',0);
out = [datevec(xx),fa(xx),fb(xx)];