For many vectors of data of different length, how do I interpolate to set them all to have the same length?

21 visualizaciones (últimos 30 días)
I'm analyzing a series of data vectors, each of which has a different number of points, but the x-coordinate of the data spans 1 to ~2800. My simulations have 1400 points, so I need to interpolate the data vectors to properly sample the y-coordinate of the data while ending up with all interpolated data vectors at a length of 1400. Are there any helpful tricks? I know "resample()" would do the trick, but I'm not able to purchase the signal processing toolbox, so that's not an option.

Respuesta aceptada

Adam Danz
Adam Danz el 3 de Sept. de 2019
Editada: Adam Danz el 3 de Sept. de 2019
Use interp1()
Demo:
xdata = 1:280;
ydata = 10:150;
xdataResamp = linspace(xdata(1),xdata(end),numel(ydata));
ydataInterp = interp1(xdataResamp,ydata,xdata);
% Visually inspect results
figure()
plot(xdataResamp,ydata, 'b-o')
hold on
plot(xdata, ydataInterp, 'r-s')
  4 comentarios
Blenndrman
Blenndrman el 4 de Sept. de 2019
Yes – I figured it out now, your initial answer was correct, and helpful, thanks!
In my actual code I have enough variables that I got confused and misapplied your solution, at first.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by