Interpolating Data from Vectors of Different Length
16 views (last 30 days)
Show older comments
Hi,
So I have several data sets where one vector is essentially a % time matrix (from 0-100%), and the other matrix is the data associated with each one of those points. I have several of these that I need to average, but the %time matrices are of different lengths. I would like to have all the time matrices to be [0:.02:1], and fit the data to that vector, however I am unsure of how to do this. Any help would be appreciated, Thanks.
0 Comments
Accepted Answer
Sven
on 20 Nov 2011
This is a job for the interp1 function:
% Make original data
oldPcntVals = [0 .1 .3 .7 .9 1];
oldYvals = [10 12 15 13 12 11]
% Set a new spacing from 0 to 1 and interpolate
newPcntVals = 0:0.02:1;
newYvals = interp1(oldPcntVals, oldYvals, newPcntVals);
% Compare the original values to these interpolated values
figure
plot(oldPcntVals, oldYvals, 'b.', newPcntVals,newYvals, 'g')
Keep in mind that the default interpolation method for interp1 is "linear". You could also set "cubic" or "spline" if you wanted to have your final output smoothly interpolate between your original data.
More Answers (0)
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!