Functions | |
if (nargin< 1) print_usage() | |
endif | if (ischar(varargin{end})) method |
elseif (ischar(varargin{end-1})) if(!isnumeric(varargin | |
!isscalar (varargin{end})) error("extrapal is expected to be a numeric scalar") | |
if (nargs==2) m | |
if (!isnumeric(m)||!isscalar(m)||floor(m)!=m) error("m is expected to be a integer scalar") | |
endfor | elseif (!isvector(varargin{1})&&nargs==(ndims(varargin{1})+1)) v |
endfor | elseif (rem(nargs, 2)==1 &&nargs==(2 *ndims(varargin{ceil(nargs/2)}))+1) nv |
else | error ("wrong number or incorrectly formatted input arguments") |
endif | if (any(!cellfun(@isvector, x))) for i |
endif | idx (1:nd) |
idx (i) | |
idx (1) | |
if (strcmp(method,"linear")) vi | |
vi (isna(vi)) | |
elseif (strcmp(method,"nearest")) yshape | |
endfor | vi (idx) |
elseif (strcmp(method,"spline")) if(any(!cellfun(@isvector | |
if (size_equal(y{:})) ly | |
endif | elseif (strcmp(method,"cubic")) error("cubic interpolation not yet implemented") |
else | error ("unrecognized interpolation method") |
!mesh (xi, yi, interpn(x, y, A.', xi, yi,"linear").') | |
plot3 (x(:), y(:), A(:),"b*") | |
!mesh (xi, yi, interpn(x, y, A.', xi, yi,"nearest").') | |
!mesh (xi, yi, interpn(x, y, A.', xi, yi,"cubic").') | |
!mesh (xi, yi, interpn(x, y, A.', xi, yi,"spline").') | |
!mesh (yi, zi, squeeze(vi(1,:,:))) | |
!assert (interpn(x, y, z, f,[.5 1.5],[.5 1.5],[.5 1.5]),[1.5, 4.5])%!assert(interpn(x | |
!assert (interpn(x, y, z, f,[.5 1.5],[.5 1.5],[.5 1.5],'spline'),[1.5, 4.5])%!assert(interpn(x | |
f | !assert (interpn(x, y, z, f, x, y, z,'nearest'), f)%!assert(interpn(x |
Variables | |
function | vi |
extrapval = NA | |
nargs = nargin | |
endif | method = varargin{end - 1} |
m = 1 | |
endif endif | sz = size (v) |
nd = ndims (v) | |
x = cell (1, nd) | |
y = cell (1, nd) | |
for | i = 1 : nd |
v = varargin{nv} | |
yidx = cell (1, nd) | |
endfor | idx = cell (1,nd) |
q = cell (1, nd) | |
endif endfunction!demo | !A = [13,-1,12 |
!x = [0,1,4] | |
!xi = linspace(min(x),max(x),17) | |
!AI = linspace(min(y),max(y),26)' | |
!hold | on = meshgrid(x,y) |
hold | off |
!yi = linspace(min(y),max(y),26)' | |
!f = @(x,y,z) x.^2 - y - z.^2 | |
!v = meshgrid (x, y, z) f (xx,yy,zz) | |
!vi = ndgrid (xi, yi, zi) interpn(x, y, z, v, xxi, yyi, zzi, 'spline') | |
!test [x, y, z] = ndgrid(0:2) | |
z | |
f | |
nearest | |
f | spline |
f !assert | ( | interpn(x, y, z, f, x, y, z,'nearest') | , | |
f | ||||
) |
!assert | ( | interpn(x, y, z, f,[.5 1.5],[.5 1.5],[.5 1.5],'spline') | ) |
!assert | ( | interpn(x, y, z, f,[.5 1.5],[.5 1.5],[.5 1.5]) | ) |
!isscalar | ( | ) |
!mesh | ( | yi | , | |
zi | , | |||
squeeze(vi(1,:,:)) | ||||
) |
elseif | ( | strcmp(method,"spline") | ) |
elseif | ( | strcmp(method,"nearest") | ) |
elseif | ( | ischar(varargin{end-1}) | ) |
else error | ( | "wrong number or incorrectly formatted input arguments" | ) |
idx | ( | 1 | ) |
idx | ( | i | ) |
if | ( | size_equal(y{:}) | ) |
if | ( | strcmp(method,"linear") | ) |
endif if | ( | any(!cellfun(@isvector, x)) | ) |
if | ( | !isnumeric(m)||!isscalar(m)||floor(m)! | = m |
) |
if | ( | nargs | = =2 |
) |
endif if | ( | ischar(varargin{end}) | ) |
if | ( | ) |
plot3 | ( | x(:) | , | |
y(:) | , | |||
A(:) | , | |||
"b*" | ||||
) |
endfor vi | ( | idx | ) |
vi | ( | isna(vi) | ) |
!demo !A = [13,-1,12 |
!AI = linspace(min(y),max(y),26)' |
!f = @(x,y,z) x.^2 - y - z.^2 |
f f !test[x, y, z] | ( | ) | = ndgrid(0:2) |
!v = meshgrid (x, y, z) f (xx,yy,zz) |
!demo !x = [0,1,4] |
!xi = linspace(min(x),max(x),17) |
!yi = linspace(min(y),max(y),26)' |
extrapval = NA |
f f |
idx = cell (1,nd) |
m = 1 |
hold off |
! hold on = meshgrid(x,y) |
q = cell (1, nd) |
f spline |
sz = size (v) |
v = varargin{nv} |
f x = cell (1, nd) |
f y = cell (1, nd) |
f z |