MATLAB: Finding corresponding data events for continuous time

data extractiontime

I have a matrix with data in one column and corresponding time intervals in the next column. Another matrix has event times. I am wanting to get the data from the first matrix that corresponds to the event time. In first column of matrix1 is frequency data and in the second column is regular intervals of time that correspond to the frequency data. Matrix2 is time points of events that correspond to the time from matrix1. I want to take the frequency data points from matrix1 based on the events that are happening in matrix2.I am looking to take data points from matrix1 for every event happening in matrix2. So its a continuous data set and I need the corresponding data point in matrix1 based on matrix2 time events. Most of the data points would in fact be between times so the time events in matrix2 would need to take the approximation of time events from matrix1 column 1 based on matrix1 column 2 time points.

Best Answer

From your description, the interp1 function would be the solution.
See if this does what you want:
D1 = load('Heath Robinson Matrix1.mat');
D2 = load('Heath Robinson Matrix2.mat');
M1 = D1.Matrix1;
M2 = D2.matrix2;
M1i = interp1(M1(:,2), M1(:,1), M2, 'linear'); % Interpolate
figure(1)
plot(M1(:,2), M1(:,1), '-b') % Plot Original Data
hold on
plot(M2, M1i, 'xr') % Plot Interpolated Data
hold off
grid