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

19 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Adam Danz
Adam Danz am 3 Sep. 2019
Bearbeitet: Adam Danz am 3 Sep. 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 Kommentare
Blenndrman
Blenndrman am 4 Sep. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by