MATLAB: Interp1 or its alternatives, working for matrices without loop

interpolationvectorization

Hi All,
I have matrices X and Y, with size(x) = [30,30000], and size(y) = [30,30000]. Columnar data in x are different between different columns, and so is y. xi is interpolation vector, with size(xi) = [60, 1]. For linear interpolation, I know I can do:
for i=1: 30000
output(:,i) = interp1(x(:,i), y(:,i), xi);
end
But it is slow to go through the 30000 loops. What is worse, x and y are daily data, and I need to do it annually. Therefore, using loop is a way too slow. I found that shared scripts like ScaleTime exists, which however do not accept x with different columnar values.
Question 1:
Is there a vecterize method to do the interpolation (linear)?
Question 2:
What about vecterized interpolation using cubic or pchip?
Many thanks,
John

Best Answer

So you're going over column by column, creating columns of 60 out of columns of 30. Assuming your xi are just exactly between the elements and exactly on the elements, you can just assume the "in between" interpolations are just the average of the two elements on either side. Thus you can just use a sliding mean filter. Use conv2(y(:,i), [.5; .5]) to give you the "in between" values, then just interleave it with the existing values. Exercise for the reader: interleave the convolution output with the original matrix. (It's like 3 lines of code or so.) Let me know if you can't figure it out and need help.
If your xi are spaced out at non-periodic oddball locations then you can't use conv2.