I have 4 grids:
kgrid
which is [77x1]x
which is [15x1]z
which is [9x1]s
which is [2x1]
Then I have a function:
kprime
which is [77x15x9x2]
I want to interpolate kprime
at some points ksim (750 x 1)
and zsim (750 x 1)
(xsim
is a scalar). I am doing:
[ks, xs, zs, ss] = ndgrid(kgrid, x, z, [1;2]);
Output = interpn(ks, xs, zs, ss, kprime, ksim, xsim, zsim, 1,'linear');
The problem with this interpolation is that the output given is for all combinations of ksim
and zsim
, meaning that the output is 750x750. I actually need an output of 750x1, meaning that instead of interpolation at all combinations of ksim
and zsim
I only need to interpolate at ksim(1,1)
and zsim(1,1)
, then ksim(2,1)
and zsim(2,1)
, then ksim(3,1)
and zsim(3,1)
, etc.
In other words, after getting Output
I am doing:
Output = diag(squeeze(Output));
I know I can use this output and then just pick the numbers I want, but this is extremely inefficient as it actually interpolates on all other points which I actually do not need. Any help appreciated.