bug in interpn for method linear and nearest
Alexander Barth
barth.alexander at gmail.com
Mon Jan 21 04:33:05 CST 2008
Hi all,
I think there are some bugs in interpn (octave 3.0.0 and current cvs).
* method = linear: in matlab I get for:
>> [x,y,z] = ndgrid(0:2);
>> f = x+y+z;
>> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5])
fi =
1.5000 4.5000
In octave:
octave:4> [x,y,z] = ndgrid(0:2);
octave:5> f = x+y+z;
octave:6> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5])
fi =
ans(:,:,1) =
1.5000 2.5000
2.5000 3.5000
ans(:,:,2) =
2.5000 3.5000
3.5000 4.5000
Matlab and octave do different things here. The coordinates of the
interpolated locations are 'ndgrid'ed in octave. (note that interp2 in
octave does not pass the interpolated locations by meshgrid).
* method = 'nearest'
The following fails in octave:
octave:7> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'nearest')
error: operator -: nonconformant arguments (op1 is 8x1, op2 is 1x8)
error: evaluating binary operator `-' near line 162, column 36
error: evaluating binary operator `>' near line 162, column 54
error: evaluating binary operator `+' near line 162, column 27
error: evaluating assignment expression near line 162, column 16
error: evaluating for command near line 161, column 5
error: evaluating if command near line 150, column 3
error: called from `interpn' in file
`/u/abarth/local/share/octave/2.9.17/m/general/interpn.m'
error: evaluating assignment expression near line 7, column 4
while in matlab:
>> fi = interpn(x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],'nearest')
fi =
3 6
* A minor issue is that the string method is transformed to lowercase a
couple of lines too late in the code.
I attached is a tentative patch. I don't fully understand interpn.m, so it
would be great if someone could confirm the modifications.
Thanks
Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080121/03238707/attachment.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interpn.patch
Type: text/x-patch
Size: 1016 bytes
Desc: not available
Url : https://www.cae.wisc.edu/pipermail/bug-octave/attachments/20080121/03238707/attachment.bin
More information about the Bug-octave
mailing list