Interpolation with interp3

I have a 3D function on grids x, y and z. Call this function ‘Fn_Value’. I would like to interpolate ‘Fn_Value’ on grids (vectors) x_interp, y_interp, z_interp. x_interp and y_interp are of the same length, whereas z_interp is of a different length from x_interp and y_interp. I don’t want to interpolate ‘Fn_Value’ for all possible values of x_interp, y_interp and z_interp, which I could accomplish with code like (equation 1):
interp3(x,y,z,Fn_Value,x_interp’,y_interp,z_interp,`spline’)
This is way more interpolation than I need. I just want, for each (x,y)-pair on the interpolation nodes (i.e. x_interp(i), y_interp(i), all i) to interpolate for all z. I could just interpolate like in equation 1 and then, for each z, take the diagonal elements of these matrices. Although this will get the job done, it seems very inefficient.
Alternatively, I can use a for loop like this:
Fn_interp = zeros(length(x_interp),length(z_interp));
for i_z=1:length(z_interp)
Fn_temp = squeeze(Fn_Value(:,:,i_z));
Fn_interp(:,i_z) = interp2(x,y,Fn_temp,x_interp,y_interp,'spline');
end
Again, this gets the job done, but the length of z_interp can get very large, so I would prefer to circumvent the use of the for loop. Does anyone have a clean resolution to this problem? Please let me know if I can provide any further information to make this question clearer. Thank you.

回答(1 个)

Jan
Jan 2011-5-18

1 个投票

You can use the profile to find out, where the actually calculations are performed - I assume INTERp2 calls SPLNCORE, which calls SPLINE. Then inspect the inputs used for the calculator and call it directly. The creation of the coefficients for the 2D-spline-interpolation consumes more time than the actually application. Therefore I assume, you can save a lot of time, if you use the coefficients repeatedly for all slices of your 3D array.

2 个评论

Is there any way to do this without a for loop?
Perhaps. Most of all it should be fast, I assume.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Interpolation 的更多信息

标签

提问:

2011-5-18

Community Treasure Hunt

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

Start Hunting!

Translated by