bug in interpn for method linear and nearest

Alexander Barth barth.alexander at gmail.com
Wed Jan 23 14:58:58 CST 2008


On Jan 22, 2008 6:03 PM, David Bateman <David.Bateman at motorola.com> wrote:
> Alexander Barth wrote:
> > Matlab returns in this case an error:
> >
> >>> [x,y,z] = ndgrid(0:2);
> >>> f = x+y+z;
> >>> interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5 2])
> >>>
> > ??? Error using ==> interpn
> > Y1,Y2,Y3, etc. must all the same size or vectors of different orientations.
> >
> > The patched octave version too:
> > octave:6> interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5 2])
> > error: interpn: incompatible size of argument number 7
> >
> > As I interprete matlab's error message (vectors of different
> > orientations), I expected the following to be ndgridded:
> >
> >
> >>> interpn(x,y,z,f,reshape([.5 1.5],[2 1 1]),reshape([.5 1.5],[1 2
> >>>
> > 1]),reshape([.5 1.5 2],[1 1 3]))
> > ??? Error using ==> interpn
> > Y1,Y2,Y3, etc. must all the same size or vectors of different orientations.
> >
> > But this seems not to be the case. As far as I have tested, we are
> > compatible relative to the acceptable input parameters (and we don't
> > produce a confusing error messages!).
> >
>
> Then in that case I should undo part of my previous proposal..
>
> >
> >> As the underlying spline function has this behavior of ndgridding the
> >> output values if yi is a vector and the values array is an NDArray and
> >> does in both Octave and Matlab, I'm not sure the right way to fix this.
> >> A quick hack would be to do the equivalent of an ND diag function to get
> >> the required values.
> >>
> >>
> >
> > I agree with that approach; to make the spline interpolation
> > compatible now and to worry about the optimization later. Do we
> > already have already an equivalent of an ND diag function?
> >
> >
>
> There is probably something faster, but I don't see it at this point.
> New patch attached
>
> D.
>
What about something like this?

    sc = sum ([1 cumprod(size (vi)(1:end-1))]);
    vi = vi(sc * [0:size(vi,1)-1] + 1);

I noticed another problem with the spline interpolation. Octave returns:

octave:5> interpn(x,y,z,f,x,y,z,'spline')
ans =

   0   3   6

while it should return the values of f.
The attached patch corrects this issue (with new test cases).

Cheers,

Alex
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interpn_spline_ndgrid.patch
Type: text/x-patch
Size: 2306 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080123/ab461c21/attachment-0001.bin 


More information about the Bug-octave mailing list