annotate scripts/general/interp2.m @ 17281:bc924baa2c4e

doc: Add new @qcode macro for code samples which are quoted. Macro handles options ("on") or properties ("position") more elegantly than @code{"text"}. * doc/interpreter/macros.texi: Add new @qcode macro. * doc/interpreter/tips.txi: Add documentation about @qcode macro. * doc/interpreter/basics.txi, doc/interpreter/container.txi, doc/interpreter/emacs.txi, doc/interpreter/errors.txi, doc/interpreter/eval.txi, doc/interpreter/expr.txi, doc/interpreter/external.txi, doc/interpreter/func.txi, doc/interpreter/grammar.txi, doc/interpreter/image.txi, doc/interpreter/install.txi, doc/interpreter/interp.txi, doc/interpreter/io.txi, doc/interpreter/matrix.txi, doc/interpreter/numbers.txi, doc/interpreter/oop.txi, doc/interpreter/package.txi, doc/interpreter/plot.txi, doc/interpreter/quad.txi, doc/interpreter/sparse.txi, doc/interpreter/strings.txi, doc/interpreter/system.txi, doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc, libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m, scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m, scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m, scripts/general/dblquad.m, scripts/general/display.m, scripts/general/genvarname.m, scripts/general/idivide.m, scripts/general/interp1.m, scripts/general/interp2.m, scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m, scripts/general/profexplore.m, scripts/general/profile.m, scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m, scripts/general/subsindex.m, scripts/general/triplequad.m, scripts/geometry/griddata.m, scripts/geometry/griddata3.m, scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m, scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m, scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m, scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m, scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m, scripts/java/javaclasspath.m, scripts/java/usejava.m, scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m, scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m, scripts/optimization/fminunc.m, scripts/optimization/fsolve.m, scripts/optimization/fzero.m, scripts/optimization/glpk.m, scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m, scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m, scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m, scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m, scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m, scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m, scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m, scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m, scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m, scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m, scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m, scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m, scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m, scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m, scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m, scripts/plot/plot.m, scripts/plot/print.m, scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m, scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m, scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m, scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m, scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m, scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m, scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m, scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m, scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m, scripts/polynomial/conv.m, scripts/polynomial/polyout.m, scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m, scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m, scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m, scripts/signal/periodogram.m, scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m, scripts/specfun/legendre.m, scripts/special-matrix/gallery.m, scripts/statistics/base/mean.m, scripts/statistics/base/moment.m, scripts/statistics/tests/cor_test.m, scripts/statistics/tests/kolmogorov_smirnov_test.m, scripts/statistics/tests/kolmogorov_smirnov_test_2.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m, scripts/statistics/tests/t_test_regression.m, scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m, scripts/statistics/tests/welch_test.m, scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m, scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m, scripts/strings/index.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/validatestring.m, scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m, scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m, scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m, scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m, scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author Rik <rik@octave.org>
date Mon, 19 Aug 2013 20:46:38 -0700
parents 049e8bbff782
children d63878346099
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13149
diff changeset
1 ## Copyright (C) 2000-2012 Kai Habel
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8828
diff changeset
2 ## Copyright (C) 2009 Jaroslav Hajek
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
3 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
4 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
5 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
9 ## your option) any later version.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
10 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
14 ## General Public License for more details.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
15 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
18 ## <http://www.gnu.org/licenses/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
19
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
20 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
21 ## @deftypefn {Function File} {@var{zi} =} interp2 (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi})
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
22 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{Z}, @var{xi}, @var{yi})
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
23 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@var{Z}, @var{n})
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
24 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method})
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
25 ## @deftypefnx {Function File} {@var{zi} =} interp2 (@dots{}, @var{method}, @var{extrapval})
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
26 ##
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
27 ## Two-dimensional interpolation. @var{x}, @var{y} and @var{z} describe a
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
28 ## surface function. If @var{x} and @var{y} are vectors their length
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
29 ## must correspondent to the size of @var{z}. @var{x} and @var{y} must be
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
30 ## monotonic. If they are matrices they must have the @code{meshgrid}
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
31 ## format.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
32 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
33 ## @table @code
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
34 ## @item interp2 (@var{x}, @var{y}, @var{Z}, @var{xi}, @var{yi}, @dots{})
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
35 ## Returns a matrix corresponding to the points described by the
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
36 ## matrices @var{xi}, @var{yi}.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
37 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
38 ## If the last argument is a string, the interpolation method can
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
39 ## be specified. The method can be @qcode{"linear"}, @qcode{"nearest"} or
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
40 ## @qcode{"cubic"}. If it is omitted @qcode{"linear"} interpolation is
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
41 ## assumed.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
42 ##
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
43 ## @item interp2 (@var{z}, @var{xi}, @var{yi})
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
44 ## Assumes @code{@var{x} = 1:rows (@var{z})} and @code{@var{y} =
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
45 ## 1:columns (@var{z})}
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
46 ##
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
47 ## @item interp2 (@var{z}, @var{n})
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
48 ## Interleaves the matrix @var{z} n-times. If @var{n} is omitted a value
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
49 ## of @code{@var{n} = 1} is assumed.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
50 ## @end table
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
51 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
52 ## The variable @var{method} defines the method to use for the
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
53 ## interpolation. It can take one of the following values
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
54 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
55 ## @table @asis
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
56 ## @item @qcode{"nearest"}
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
57 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
58 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
59 ## @item @qcode{"linear"}
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
60 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
61 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
62 ## @item @qcode{"pchip"}
11536
702dbd0c53f5 Add undocumented ppder, ppint, ppjumps functions to documentation.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
63 ## Piecewise cubic Hermite interpolating polynomial.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
64 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
65 ## @item @qcode{"cubic"}
6218
c1b66b74937d [project @ 2006-12-27 17:43:50 by jwe]
jwe
parents: 6157
diff changeset
66 ## Cubic interpolation from four nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
67 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 15467
diff changeset
68 ## @item @qcode{"spline"}
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11589
diff changeset
69 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
70 ## throughout the curve.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
71 ## @end table
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
72 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
73 ## If a scalar value @var{extrapval} is defined as the final value, then
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
74 ## values outside the mesh as set to this value. Note that in this case
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
75 ## @var{method} must be defined as well. If @var{extrapval} is not
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
76 ## defined then NA is assumed.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
77 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
78 ## @seealso{interp1}
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
79 ## @end deftypefn
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
80
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
81 ## Author: Kai Habel <kai.habel@gmx.de>
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
82 ## 2005-03-02 Thomas Weber <weber@num.uni-sb.de>
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
83 ## * Add test cases
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
84 ## 2005-03-02 Paul Kienzle <pkienzle@users.sf.net>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
85 ## * Simplify
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
86 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
87 ## * Modified demo and test for new gnuplot interface
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
88 ## 2005-09-07 Hoxide <hoxide_dirac@yahoo.com.cn>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
89 ## * Add bicubic interpolation method
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
90 ## * Fix the eat line bug when the last element of XI or YI is
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
91 ## negative or zero.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
92 ## 2005-11-26 Pierre Baldensperger <balden@libertysurf.fr>
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
93 ## * Rather big modification (XI,YI no longer need to be
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
94 ## "meshgridded") to be consistent with the help message
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
95 ## above and for compatibility.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
96
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
97 function ZI = interp2 (varargin)
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
98 Z = X = Y = XI = YI = n = [];
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
99 method = "linear";
6742
ebf96cc00ee9 [project @ 2007-06-18 16:27:52 by jwe]
jwe
parents: 6702
diff changeset
100 extrapval = NA;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
101
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
102 switch (nargin)
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
103 case 1
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
104 Z = varargin{1};
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
105 n = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
106 case 2
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
107 if (ischar (varargin{2}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
108 [Z, method] = deal (varargin{:});
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
109 n = 1;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
110 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
111 [Z, n] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
112 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
113 case 3
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
114 if (ischar (varargin{3}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
115 [Z, n, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
116 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
117 [Z, XI, YI] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
118 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
119 case 4
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
120 if (ischar (varargin{4}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
121 [Z, XI, YI, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
122 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
123 [Z, n, method, extrapval] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
124 endif
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
125 case 5
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
126 if (ischar (varargin{4}))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
127 [Z, XI, YI, method, extrapval] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
128 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
129 [X, Y, Z, XI, YI] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
130 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
131 case 6
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
132 [X, Y, Z, XI, YI, method] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
133 case 7
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
134 [X, Y, Z, XI, YI, method, extrapval] = deal (varargin{:});
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
135 otherwise
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
136 print_usage ();
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
137 endswitch
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
138
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
139 ## Type checking.
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
140 if (!ismatrix (Z))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
141 error ("interp2: Z must be a matrix");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
142 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
143 if (!isempty (n) && !isscalar (n))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
144 error ("interp2: N must be a scalar");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
145 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
146 if (!ischar (method))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
147 error ("interp2: METHOD must be a string");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
148 endif
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
149 if (ischar (extrapval) || strcmp (extrapval, "extrap"))
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
150 extrapval = [];
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
151 elseif (!isscalar (extrapval))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
152 error ("interp2: EXTRAPVAL must be a scalar");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
153 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
154
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
155 ## Define X, Y, XI, YI if needed
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
156 [zr, zc] = size (Z);
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
157 if (isempty (X))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
158 X = 1:zc;
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
159 Y = 1:zr;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
160 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
161 if (! isnumeric (X) || ! isnumeric (Y))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
162 error ("interp2: X, Y must be numeric matrices");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
163 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
164 if (! isempty (n))
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
165 ## Calculate the interleaved input vectors.
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
166 p = 2^n;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
167 XI = (p:p*zc)/p;
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
168 YI = (p:p*zr)'/p;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
169 endif
5838
376e02b2ce70 [project @ 2006-06-01 20:23:53 by jwe]
jwe
parents: 5837
diff changeset
170 if (! isnumeric (XI) || ! isnumeric (YI))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
171 error ("interp2: XI, YI must be numeric");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
172 endif
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
173
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
174
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
175 if (strcmp (method, "linear") || strcmp (method, "nearest") ...
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
176 || strcmp (method, "pchip"))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
177
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
178 ## If X and Y vectors produce a grid from them
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
179 if (isvector (X) && isvector (Y))
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
180 X = X(:); Y = Y(:);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
181 elseif (size_equal (X, Y))
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
182 X = X(1,:)'; Y = Y(:,1);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
183 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
184 error ("interp2: X and Y must be matrices of same size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
185 endif
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
186 if (columns (Z) != length (X) || rows (Z) != length (Y))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
187 error ("interp2: X and Y size must match the dimensions of Z");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
188 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
189
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
190 ## If Xi and Yi are vectors of different orientation build a grid
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
191 if ((rows (XI) == 1 && columns (YI) == 1)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
192 || (columns (XI) == 1 && rows (YI) == 1))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
193 [XI, YI] = meshgrid (XI, YI);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
194 elseif (! size_equal (XI, YI))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
195 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
196 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
197
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
198 ## if XI, YI are vectors, X and Y should share their orientation.
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
199 if (rows (XI) == 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
200 if (rows (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
201 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
202 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
203 if (rows (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
204 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
205 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
206 elseif (columns (XI) == 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
207 if (columns (X) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
208 X = X.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
209 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
210 if (columns (Y) != 1)
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
211 Y = Y.';
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
212 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
213 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
214
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
215 xidx = lookup (X, XI, "lr");
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
216 yidx = lookup (Y, YI, "lr");
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
217
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
218 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
219 ## each quad satisfies the equation z(x,y)=a+b*x+c*y+d*xy
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
220 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
221 ## a-b
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
222 ## | |
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
223 ## c-d
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
224 a = Z(1:(zr - 1), 1:(zc - 1));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
225 b = Z(1:(zr - 1), 2:zc) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
226 c = Z(2:zr, 1:(zc - 1)) - a;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
227 d = Z(2:zr, 2:zc) - a - b - c;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
228
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
229 ## scale XI, YI values to a 1-spaced grid
10326
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
230 Xsc = (XI - X(xidx)) ./ (diff (X)(xidx));
ade59ae10e80 slight optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10320
diff changeset
231 Ysc = (YI - Y(yidx)) ./ (diff (Y)(yidx));
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
232
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
233 ## Get 2D index.
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
234 idx = sub2ind (size (a), yidx, xidx);
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
235 ## We can dispose of the 1D indices at this point to save memory.
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
236 clear xidx yidx;
10328
2210d3070543 further memory optimization in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 10326
diff changeset
237
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
238 ## apply plane equation
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
239 ZI = a(idx) + b(idx).*Xsc + c(idx).*Ysc + d(idx).*Xsc.*Ysc;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
240
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
241 elseif (strcmp (method, "nearest"))
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
242 ii = (XI - X(xidx) >= X(xidx + 1) - XI);
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
243 jj = (YI - Y(yidx) >= Y(yidx + 1) - YI);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
244 idx = sub2ind (size (Z), yidx+jj, xidx+ii);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
245 ZI = Z(idx);
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
246
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
247 elseif (strcmp (method, "pchip"))
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
248
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
249 if (length (X) < 2 || length (Y) < 2)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
250 error ("interp2: pchip2 requires at least 2 points in each dimension");
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
251 endif
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
252
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
253 ## first order derivatives
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
254 DX = __pchip_deriv__ (X, Z, 2);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
255 DY = __pchip_deriv__ (Y, Z, 1);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
256 ## Compute mixed derivatives row-wise and column-wise, use the average.
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
257 DXY = (__pchip_deriv__ (X, DY, 2) + __pchip_deriv__ (Y, DX, 1))/2;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
258
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
259 ## do the bicubic interpolation
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
260 hx = diff (X); hx = hx(xidx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
261 hy = diff (Y); hy = hy(yidx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
262
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
263 tx = (XI - X(xidx)) ./ hx;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
264 ty = (YI - Y(yidx)) ./ hy;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
265
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
266 ## construct the cubic hermite base functions in x, y
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
267
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
268 ## formulas:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
269 ## b{1,1} = ( 2*t.^3 - 3*t.^2 + 1);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
270 ## b{2,1} = h.*( t.^3 - 2*t.^2 + t );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
271 ## b{1,2} = (-2*t.^3 + 3*t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
272 ## b{2,2} = h.*( t.^3 - t.^2 );
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
273
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
274 ## optimized equivalents of the above:
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
275 t1 = tx.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
276 t2 = tx.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
277 xb{2,2} = hx.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
278 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
279 xb{2,1} = hx.*(t1 + tx);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
280 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
281 xb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
282 xb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
283
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
284 t1 = ty.^2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
285 t2 = ty.*t1 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
286 yb{2,2} = hy.*t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
287 t1 = t2 - t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
288 yb{2,1} = hy.*(t1 + ty);
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
289 t2 += t1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
290 yb{1,2} = -t2;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
291 yb{1,1} = t2 + 1;
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
292
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
293 ZI = zeros (size (XI));
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
294 for i = 1:2
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
295 for j = 1:2
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
296 zidx = sub2ind (size (Z), yidx+(j-1), xidx+(i-1));
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
297 ZI += xb{1,i} .* yb{1,j} .* Z(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
298 ZI += xb{2,i} .* yb{1,j} .* DX(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
299 ZI += xb{1,i} .* yb{2,j} .* DY(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
300 ZI += xb{2,i} .* yb{2,j} .* DXY(zidx);
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
301 endfor
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
302 endfor
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
303
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
304 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
305
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
306 if (! isempty (extrapval))
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
307 ## set points outside the table to 'extrapval'
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
308 if (X (1) < X (end))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
309 if (Y (1) < Y (end))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
310 ZI (XI < X(1,1) | XI > X(end) | YI < Y(1,1) | YI > Y(end)) = ...
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
311 extrapval;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
312 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
313 ZI (XI < X(1) | XI > X(end) | YI < Y(end) | YI > Y(1)) = ...
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
314 extrapval;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
315 endif
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
316 else
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
317 if (Y (1) < Y (end))
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
318 ZI (XI < X(end) | XI > X(1) | YI < Y(1) | YI > Y(end)) = ...
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
319 extrapval;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
320 else
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
321 ZI (XI < X(1,end) | XI > X(1) | YI < Y(end) | YI > Y(1)) = ...
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
322 extrapval;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
323 endif
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
324 endif
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
325 endif
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6742
diff changeset
326
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
327 else
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
328
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
329 ## Check dimensions of X and Y
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
330 if (isvector (X) && isvector (Y))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
331 X = X(:).';
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
332 Y = Y(:);
11108
78a6016875ed general/interp2.m: Fix input checks for cubic interpolation (bug #31352, part 1).
Gunnar Farneback <gunnar@lysator.liu.se>
parents: 10906
diff changeset
333 if (!isequal ([length(Y), length(X)], size(Z)))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
334 error ("interp2: X and Y size must match the dimensions of Z");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
335 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
336 elseif (!size_equal (X, Y))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
337 error ("interp2: X and Y must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
338 if (! size_equal (X, Z))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
339 error ("interp2: X and Y size must match the dimensions of Z");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
340 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
341 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
342
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
343 ## Check dimensions of XI and YI
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
344 if (isvector (XI) && isvector (YI) && ! size_equal (XI, YI))
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
345 XI = XI(:).';
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
346 YI = YI(:);
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
347 [XI, YI] = meshgrid (XI, YI);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
348 elseif (! size_equal (XI, YI))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
349 error ("interp2: XI and YI must be matrices of equal size");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
350 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
351
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
352 if (strcmp (method, "cubic"))
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
353 if (isgriddata (XI) && isgriddata (YI'))
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
354 ZI = bicubic (X, Y, Z, XI (1, :), YI (:, 1), extrapval);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
355 elseif (isgriddata (X) && isgriddata (Y'))
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
356 ## Allocate output
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
357 ZI = zeros (size (X));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
358
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
359 ## Find inliers
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
360 inside = !(XI < X (1) | XI > X (end) | YI < Y (1) | YI > Y (end));
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
361
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
362 ## Scale XI and YI to match indices of Z
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
363 XI = (columns (Z) - 1) * (XI - X (1)) / (X (end) - X (1)) + 1;
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
364 YI = (rows (Z) - 1) * (YI - Y (1)) / (Y (end) - Y (1)) + 1;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
365
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
366 ## Start the real work
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
367 K = floor (XI);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
368 L = floor (YI);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
369
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
370 ## Coefficients
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
371 AY1 = bc ((YI - L + 1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
372 AX1 = bc ((XI - K + 1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
373 AY0 = bc ((YI - L + 0));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
374 AX0 = bc ((XI - K + 0));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
375 AY_1 = bc ((YI - L - 1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
376 AX_1 = bc ((XI - K - 1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
377 AY_2 = bc ((YI - L - 2));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
378 AX_2 = bc ((XI - K - 2));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
379
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
380 ## Perform interpolation
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
381 sz = size (Z);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
382 ZI = AY_2 .* AX_2 .* Z (sym_sub2ind (sz, L+2, K+2)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
383 + AY_2 .* AX_1 .* Z (sym_sub2ind (sz, L+2, K+1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
384 + AY_2 .* AX0 .* Z (sym_sub2ind (sz, L+2, K)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
385 + AY_2 .* AX1 .* Z (sym_sub2ind (sz, L+2, K-1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
386 + AY_1 .* AX_2 .* Z (sym_sub2ind (sz, L+1, K+2)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
387 + AY_1 .* AX_1 .* Z (sym_sub2ind (sz, L+1, K+1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
388 + AY_1 .* AX0 .* Z (sym_sub2ind (sz, L+1, K)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
389 + AY_1 .* AX1 .* Z (sym_sub2ind (sz, L+1, K-1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
390 + AY0 .* AX_2 .* Z (sym_sub2ind (sz, L, K+2)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
391 + AY0 .* AX_1 .* Z (sym_sub2ind (sz, L, K+1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
392 + AY0 .* AX0 .* Z (sym_sub2ind (sz, L, K)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
393 + AY0 .* AX1 .* Z (sym_sub2ind (sz, L, K-1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
394 + AY1 .* AX_2 .* Z (sym_sub2ind (sz, L-1, K+2)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
395 + AY1 .* AX_1 .* Z (sym_sub2ind (sz, L-1, K+1)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
396 + AY1 .* AX0 .* Z (sym_sub2ind (sz, L-1, K)) ...
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
397 + AY1 .* AX1 .* Z (sym_sub2ind (sz, L-1, K-1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
398 ZI (!inside) = extrapval;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
399
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
400 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
401 error ("interp2: input data must have 'meshgrid' format");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
402 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
403
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
404 elseif (strcmp (method, "spline"))
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
405 if (isgriddata (XI) && isgriddata (YI'))
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
406 ZI = __splinen__ ({Y(:,1).', X(1,:)}, Z, {YI(:,1), XI(1,:)}, extrapval,
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
407 "spline");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
408 else
15466
d174210ce1ec use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents: 14138
diff changeset
409 error ("interp2: input data must have 'meshgrid' format");
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
410 endif
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
411 else
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 11108
diff changeset
412 error ("interp2: interpolation METHOD not recognized");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
413 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
414
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
415 endif
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
416 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
417
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
418 function b = isgriddata (X)
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
419 d1 = diff (X, 1, 1);
10780
6e7590d003dc Fix bugs in interp2 (bug #29601)
Thorsten Meyer <thorsten.meyier@gmx.de>
parents: 10635
diff changeset
420 b = all (d1 (:) == 0);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
421 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
422
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
423 ## Compute the bicubic interpolation coefficients
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
424 function o = bc (x)
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
425 x = abs (x);
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
426 o = zeros (size (x));
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
427 idx1 = (x < 1);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
428 idx2 = !idx1 & (x < 2);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
429 o(idx1) = 1 - 2.*x(idx1).^2 + x(idx1).^3;
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
430 o(idx2) = 4 - 8.*x(idx2) + 5.*x(idx2).^2 - x(idx2).^3;
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
431 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
432
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
433 ## This version of sub2ind behaves as if the data was symmetrically padded
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
434 function ind = sym_sub2ind (sz, Y, X)
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
435 Y (Y < 1) = 1 - Y (Y < 1);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
436 while (any (Y (:) > 2 * sz (1)))
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
437 Y (Y > 2 * sz (1)) = round (Y (Y > 2 * sz (1)) / 2);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
438 endwhile
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
439 Y (Y > sz (1)) = 1 + 2 * sz (1) - Y (Y > sz (1));
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
440 X (X < 1) = 1 - X (X < 1);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
441 while (any (X (:) > 2 * sz (2)))
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
442 X (X > 2 * sz (2)) = round (X (X > 2 * sz (2)) / 2);
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
443 endwhile
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
444 X (X > sz (2)) = 1 + 2 * sz (2) - X (X > sz (2));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
445 ind = sub2ind (sz, Y, X);
9755
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
446 endfunction
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
447
4f4873f6f873 general/interp2.m: improved error checking and support for bicubic interpolation when X and Y are meshgrid format
Soren Hauberg <hauberg@gmail.com>
parents: 9399
diff changeset
448
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
449 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
450 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
451 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
452 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
453 %! x = [0,1,4]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
454 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
455 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
456 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
457 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
458 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
459
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
460 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
461 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
462 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
463 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
464 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
465 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
466 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
467 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "linear"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
468 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
469 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
470
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
471 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
472 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
473 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
474 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
475 %! x = [0,1,4]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
476 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
477 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
478 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
479 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
480 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
481
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
482 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
483 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
484 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
485 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
486 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
487 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
488 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
489 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "nearest"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
490 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
491 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
492
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
493 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
494 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
495 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
496 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
497 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
498 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
499 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
500 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
501 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
502 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
503
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
504 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
505 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
506 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
507 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
508 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
509 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
510 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
511 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "pchip"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
512 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
513 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
514
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
515 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
516 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
517 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
518 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
519 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
520 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
521 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
522 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
523 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
524 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
525
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
526 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
527 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
528 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
529 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
530 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
531 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
532 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
533 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "cubic"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
534 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
535 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
536
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
537 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
538 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
539 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
540 %! A = [13,-1,12;5,4,3;1,6,2];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
541 %! x = [0,1,2]; y = [10,11,12];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
542 %! xi = linspace (min (x), max (x), 17);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
543 %! yi = linspace (min (y), max (y), 26)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
544 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
545 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
546 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents: 6448
diff changeset
547
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
548 %!demo
14247
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
549 %! clf;
c4fa5e0b6193 test: Make surface demos reproducible by setting colormap to default at start of demo.
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
550 %! colormap ("default");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
551 %! [x,y,A] = peaks (10);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
552 %! x = x(1,:)'; y = y(:,1);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
553 %! xi = linspace (min (x), max (x), 41);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
554 %! yi = linspace (min (y), max (y), 41)';
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
555 %! mesh (xi,yi,interp2 (x,y,A,xi,yi, "spline"));
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
556 %! [x,y] = meshgrid (x,y);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
557 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
8712
010e15c7be9a support pchip method in interp2
Jaroslav Hajek <highegg@gmail.com>
parents: 8479
diff changeset
558
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
559 %!test % simple test
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
560 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
561 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
562 %! [X, Y] = meshgrid (x, y);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
563 %! Orig = X.^2 + Y.^3;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
564 %! xi = [1.2,2, 1.5];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
565 %! yi = [6.2, 4.0, 5.0]';
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
566 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
567 %! Expected = ...
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
568 %! [243, 245.4, 243.9;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
569 %! 65.6, 68, 66.5;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
570 %! 126.6, 129, 127.5];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
571 %! Result = interp2 (x,y,Orig, xi, yi);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
572 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
573 %! assert (Result, Expected, 1000*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
574
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
575 %!test % 2^n form
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
576 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
577 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
578 %! [X, Y] = meshgrid (x, y);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
579 %! Orig = X.^2 + Y.^3;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
580 %! xi = [1:0.25:3]; yi = [4:0.25:7]';
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
581 %! Expected = interp2 (x,y,Orig, xi, yi);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
582 %! Result = interp2 (Orig, 2);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11536
diff changeset
583 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
584 %! assert (Result, Expected, 10*eps);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
585
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
586 %!test % matrix slice
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
587 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
588 %! assert (interp2 (A,[1:4],[1:4]), [1,1,1,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
589
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
590 %!test % non-gridded XI,YI
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
591 %! A = eye (4);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
592 %! assert (interp2 (A,[1,2;3,4],[1,3;2,4]), [1,0;0,1]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
593
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
594 %!test % for values outside of boundaries
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
595 %! x = [1,2,3];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
596 %! y = [4,5,6,7];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
597 %! [X, Y] = meshgrid (x,y);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
598 %! Orig = X.^2 + Y.^3;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
599 %! xi = [0,4];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
600 %! yi = [3,8]';
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
601 %! assert (interp2 (x,y,Orig, xi, yi), [NA,NA;NA,NA]);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
602 %! assert (interp2 (x,y,Orig, xi, yi,"linear", 0), [0,0;0,0]);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
603
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
604 %!test % for values at boundaries
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
605 %! A=[1,2;3,4];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
606 %! x=[0,1];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
607 %! y=[2,3]';
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
608 %! assert (interp2 (x,y,A,x,y,"linear"), A);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
609 %! assert (interp2 (x,y,A,x,y,"nearest"), A);
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
610
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
611 %!test % for Matlab-compatible rounding for 'nearest'
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
612 %! X = meshgrid (1:4);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
613 %! assert (interp2 (X, 2.5, 2.5, "nearest"), 3);
10427
62bb59f927b1 scripts/general/interp2.m, scripts/general/interpn.m: For nearest neighbour interpolation ceil (instead of floor) at the center of the data intervals to be compatible with Matlab. Add test.
Soren Hauberg <hauberg@gmail.com>
parents: 10328
diff changeset
614
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
615 %!shared z, zout, tol
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
616 %! z = [1 3 5; 3 5 7; 5 7 9];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
617 %! zout = [1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8; 5 6 7 8 9];
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
618 %! tol = 2 * eps;
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
619 %!assert (interp2 (z), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
620 %!assert (interp2 (z, "linear"), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
621 %!assert (interp2 (z, "pchip"), zout, tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
622 %!assert (interp2 (z, "cubic"), zout, 10 * tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
623 %!assert (interp2 (z, "spline"), zout, tol)
13149
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
624 %!assert (interp2 (z, [2 3 1], [2 2 2]', "linear"), repmat ([5, 7, 3], [3, 1]), tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
625 %!assert (interp2 (z, [2 3 1], [2 2 2]', "pchip"), repmat ([5, 7, 3], [3, 1]), tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
626 %!assert (interp2 (z, [2 3 1], [2 2 2]', "cubic"), repmat ([5, 7, 3], [3, 1]), 10 * tol)
ab17591254fc scripts/general/interp2.m: Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
627 %!assert (interp2 (z, [2 3 1], [2 2 2]', "spline"), repmat ([5, 7, 3], [3, 1]), tol)
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
628 %!assert (interp2 (z, [2 3 1], [2 2 2], "linear"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
629 %!assert (interp2 (z, [2 3 1], [2 2 2], "pchip"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
630 %!assert (interp2 (z, [2 3 1], [2 2 2], "cubic"), [5 7 3], 10 * tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
631 %!assert (interp2 (z, [2 3 1], [2 2 2], "spline"), [5 7 3], tol)
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
632