Finding corresponding data events for continuous time
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Krispy Scripts
el 6 de Abr. de 2016
Comentada: Star Strider
el 26 de Abr. de 2016
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.
2 comentarios
Star Strider
el 6 de Abr. de 2016
I’m still confused. Do you want the closest value in Matrix2 to the values in column #2 in ‘Matrix1’, the previous value, the following value, or something else?
An example would definitely help.
Respuesta aceptada
Star Strider
el 6 de Abr. de 2016
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
4 comentarios
Star Strider
el 26 de Abr. de 2016
I use the 'linear' method as a default method in my Answers. There are several others, such as 'spline' and 'pchip' that might be more appropriate for your data. See the documentation for interp1 for the details.
Más respuestas (0)
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!