Interpolating Data from Vectors of Different Length

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.

 채택된 답변

Sven
Sven 2011년 11월 20일
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.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

태그

질문:

2011년 11월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by