MATLAB Answers

Fast linear matrix interpolation for time data NOT equally spaced

3 views (last 30 days)
Spigge
Spigge on 15 Aug 2013
I desperately need a fast linear matrix interpolation function for NOT equally spaced time data. Matlab's interp1 is slow and your contribution ScaleTime, albeit very fast, only accepts equally spaced time data (right?). Any suggestions?
Thanks,
Fredrik

  0 Comments

Sign in to comment.

Accepted Answer

Jan
Jan on 15 Aug 2013
Edited: Jan on 15 Aug 2013
I assume, you mean FEX: ScaleTime. The new version is still in the pipeline. But this works efficiently for not equally spaced data as long as X is sorted:
function Yi = myLinearInterp(X, Y, Xi)
% X and Xi are column vectors, Y a matrix with data along the columns
[dummy, Bin] = histc(Xi, X); %#ok<ASGLU>
H = diff(X); % Original step size
% Extra treatment if last element is on the boundary:
sizeY = size(Y);
if Bin(length(Bin)) >= sizeY(1)
Bin(length(Bin)) = sizeY(1) - 1;
end
Xj = Bin + (Xi - X(Bin)) ./ H(Bin);
Yi = ScaleTime(Y, Xj);
A full M-version can be found here.

  1 Comment

Spigge
Spigge on 16 Aug 2013
It works great, 5 x faster than interp1 using my matrix data. This means I can do the calculations I need without reducing the framerate in my application. Many thanks!
Fredrik

Sign in to comment.

More Answers (0)

Sign in to answer this question.