annotate scripts/general/interpn.m @ 14363:f3d52523cde1

Use Octave coding conventions in all m-file %!test blocks * wavread.m, acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, accumarray.m, accumdim.m, bitcmp.m, bitget.m, bitset.m, blkdiag.m, cart2pol.m, cart2sph.m, celldisp.m, chop.m, circshift.m, colon.m, common_size.m, cplxpair.m, cumtrapz.m, curl.m, dblquad.m, deal.m, divergence.m, flipdim.m, fliplr.m, flipud.m, genvarname.m, gradient.m, idivide.m, int2str.m, interp1.m, interp1q.m, interp2.m, interp3.m, interpft.m, interpn.m, isa.m, isdir.m, isequal.m, isequalwithequalnans.m, issquare.m, logspace.m, nargchk.m, narginchk.m, nargoutchk.m, nextpow2.m, nthargout.m, num2str.m, pol2cart.m, polyarea.m, postpad.m, prepad.m, profile.m, profshow.m, quadgk.m, quadv.m, randi.m, rat.m, repmat.m, rot90.m, rotdim.m, shift.m, shiftdim.m, sph2cart.m, structfun.m, trapz.m, triplequad.m, convhull.m, dsearch.m, dsearchn.m, griddata3.m, griddatan.m, rectint.m, tsearchn.m, __makeinfo__.m, doc.m, get_first_help_sentence.m, help.m, type.m, unimplemented.m, which.m, imread.m, imwrite.m, dlmwrite.m, fileread.m, is_valid_file_id.m, strread.m, textread.m, textscan.m, commutation_matrix.m, cond.m, condest.m, cross.m, duplication_matrix.m, expm.m, housh.m, isdefinite.m, ishermitian.m, issymmetric.m, logm.m, normest.m, null.m, onenormest.m, orth.m, planerot.m, qzhess.m, rank.m, rref.m, trace.m, vech.m, ans.m, bincoeff.m, bug_report.m, bzip2.m, comma.m, compare_versions.m, computer.m, edit.m, fileparts.m, fullfile.m, getfield.m, gzip.m, info.m, inputname.m, isappdata.m, isdeployed.m, ismac.m, ispc.m, isunix.m, list_primes.m, ls.m, mexext.m, namelengthmax.m, news.m, orderfields.m, paren.m, recycle.m, rmappdata.m, semicolon.m, setappdata.m, setfield.m, substruct.m, symvar.m, ver.m, version.m, warning_ids.m, xor.m, fminbnd.m, fsolve.m, fzero.m, lsqnonneg.m, optimset.m, pqpnonneg.m, sqp.m, matlabroot.m, __gnuplot_drawnow__.m, __plt_get_axis_arg__.m, ancestor.m, cla.m, clf.m, close.m, colorbar.m, colstyle.m, comet3.m, contourc.m, figure.m, gca.m, gcbf.m, gcbo.m, gcf.m, ginput.m, graphics_toolkit.m, gtext.m, hggroup.m, hist.m, hold.m, isfigure.m, ishghandle.m, ishold.m, isocolors.m, isonormals.m, isosurface.m, isprop.m, legend.m, line.m, loglog.m, loglogerr.m, meshgrid.m, ndgrid.m, newplot.m, orient.m, patch.m, plot3.m, plotyy.m, __print_parse_opts__.m, quiver3.m, refreshdata.m, ribbon.m, semilogx.m, semilogxerr.m, semilogy.m, stem.m, stem3.m, subplot.m, title.m, uigetfile.m, view.m, whitebg.m, compan.m, conv.m, deconv.m, mkpp.m, mpoles.m, pchip.m, poly.m, polyaffine.m, polyder.m, polyfit.m, polygcd.m, polyint.m, polyout.m, polyval.m, polyvalm.m, ppder.m, ppint.m, ppjumps.m, ppval.m, residue.m, roots.m, spline.m, intersect.m, ismember.m, powerset.m, setdiff.m, setxor.m, union.m, unique.m, autoreg_matrix.m, bartlett.m, blackman.m, detrend.m, fftconv.m, fftfilt.m, fftshift.m, freqz.m, hamming.m, hanning.m, ifftshift.m, sinc.m, sinetone.m, sinewave.m, unwrap.m, bicg.m, bicgstab.m, gmres.m, gplot.m, nonzeros.m, pcg.m, pcr.m, spaugment.m, spconvert.m, spdiags.m, speye.m, spfun.m, spones.m, sprand.m, sprandsym.m, spstats.m, spy.m, svds.m, treelayout.m, bessel.m, beta.m, betaln.m, factor.m, factorial.m, isprime.m, lcm.m, legendre.m, nchoosek.m, nthroot.m, perms.m, pow2.m, primes.m, reallog.m, realpow.m, realsqrt.m, hadamard.m, hankel.m, hilb.m, invhilb.m, magic.m, rosser.m, vander.m, __finish__.m, center.m, cloglog.m, corr.m, cov.m, gls.m, histc.m, iqr.m, kendall.m, kurtosis.m, logit.m, mahalanobis.m, mean.m, meansq.m, median.m, mode.m, moment.m, ols.m, ppplot.m, prctile.m, probit.m, quantile.m, range.m, ranks.m, run_count.m, runlength.m, skewness.m, spearman.m, statistics.m, std.m, table.m, var.m, zscore.m, betacdf.m, betainv.m, betapdf.m, betarnd.m, binocdf.m, binoinv.m, binopdf.m, binornd.m, cauchy_cdf.m, cauchy_inv.m, cauchy_pdf.m, cauchy_rnd.m, chi2cdf.m, chi2inv.m, chi2pdf.m, chi2rnd.m, discrete_cdf.m, discrete_inv.m, discrete_pdf.m, discrete_rnd.m, empirical_cdf.m, empirical_inv.m, empirical_pdf.m, empirical_rnd.m, expcdf.m, expinv.m, exppdf.m, exprnd.m, fcdf.m, finv.m, fpdf.m, frnd.m, gamcdf.m, gaminv.m, gampdf.m, gamrnd.m, geocdf.m, geoinv.m, geopdf.m, geornd.m, hygecdf.m, hygeinv.m, hygepdf.m, hygernd.m, kolmogorov_smirnov_cdf.m, laplace_cdf.m, laplace_inv.m, laplace_pdf.m, laplace_rnd.m, logistic_cdf.m, logistic_inv.m, logistic_pdf.m, logistic_rnd.m, logncdf.m, logninv.m, lognpdf.m, lognrnd.m, nbincdf.m, nbininv.m, nbinpdf.m, nbinrnd.m, normcdf.m, norminv.m, normpdf.m, normrnd.m, poisscdf.m, poissinv.m, poisspdf.m, poissrnd.m, stdnormal_cdf.m, stdnormal_inv.m, stdnormal_pdf.m, stdnormal_rnd.m, tcdf.m, tinv.m, tpdf.m, trnd.m, unidcdf.m, unidinv.m, unidpdf.m, unidrnd.m, unifcdf.m, unifinv.m, unifpdf.m, unifrnd.m, wblcdf.m, wblinv.m, wblpdf.m, wblrnd.m, kolmogorov_smirnov_test.m, kruskal_wallis_test.m, base2dec.m, bin2dec.m, blanks.m, cstrcat.m, deblank.m, dec2base.m, dec2bin.m, dec2hex.m, findstr.m, hex2dec.m, index.m, isletter.m, mat2str.m, rindex.m, str2num.m, strcat.m, strjust.m, strmatch.m, strsplit.m, strtok.m, strtrim.m, strtrunc.m, substr.m, validatestring.m, demo.m, example.m, fail.m, speed.m, addtodate.m, asctime.m, clock.m, ctime.m, date.m, datenum.m, datetick.m, datevec.m, eomday.m, etime.m, is_leap_year.m, now.m: Use Octave coding conventions in all m-file %!test blocks
author Rik <octave@nomad.inbox5.com>
date Mon, 13 Feb 2012 07:29:44 -0800
parents 7277fe922e99
children 5d3a684236b0
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: 13173
diff changeset
1 ## Copyright (C) 2007-2012 David Bateman
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
2 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
4 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
6 ## 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
7 ## 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
8 ## your option) any later version.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
9 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
14 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
15 ## 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
16 ## 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
17 ## <http://www.gnu.org/licenses/>.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
18
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
19 ## -*- texinfo -*-
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10821
diff changeset
20 ## @deftypefn {Function File} {@var{vi} =} interpn (@var{x1}, @var{x2}, @dots{}, @var{v}, @var{y1}, @var{y2}, @dots{})
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
21 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v}, @var{y1}, @var{y2}, @dots{})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
22 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v}, @var{m})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
23 ## @deftypefnx {Function File} {@var{vi} =} interpn (@var{v})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
24 ## @deftypefnx {Function File} {@var{vi} =} interpn (@dots{}, @var{method})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
25 ## @deftypefnx {Function File} {@var{vi} =} interpn (@dots{}, @var{method}, @var{extrapval})
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
26 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
27 ## Perform @var{n}-dimensional interpolation, where @var{n} is at least two.
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
28 ## Each element of the @var{n}-dimensional array @var{v} represents a value
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
29 ## at a location given by the parameters @var{x1}, @var{x2}, @dots{}, @var{xn}.
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
30 ## The parameters @var{x1}, @var{x2}, @dots{}, @var{xn} are either
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
31 ## @var{n}-dimensional arrays of the same size as the array @var{v} in
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
32 ## the "ndgrid" format or vectors. The parameters @var{y1}, etc. respect a
9209
923c7cb7f13f Simplify TeXinfo files by eliminating redundant @iftex followed by @tex construction.
Rik <rdrider0-list@yahoo.com>
parents: 9070
diff changeset
33 ## similar format to @var{x1}, etc., and they represent the points at which
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
34 ## the array @var{vi} is interpolated.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
35 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
36 ## If @var{x1}, @dots{}, @var{xn} are omitted, they are assumed to be
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
37 ## @code{x1 = 1 : size (@var{v}, 1)}, etc. If @var{m} is specified, then
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
38 ## the interpolation adds a point half way between each of the interpolation
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
39 ## points. This process is performed @var{m} times. If only @var{v} is
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
40 ## specified, then @var{m} is assumed to be @code{1}.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
41 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
42 ## Method is one of:
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
43 ##
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
44 ## @table @asis
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
45 ## @item "nearest"
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
46 ## Return the nearest neighbor.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
47 ##
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
48 ## @item "linear"
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
49 ## Linear interpolation from nearest neighbors.
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
50 ##
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
51 ## @item "cubic"
9070
e9dc2ed2ec0f Cleanup documentation for poly.texi, interp.texi, geometry.texi
Rik <rdrider0-list@yahoo.com>
parents: 9051
diff changeset
52 ## Cubic interpolation from four nearest neighbors (not implemented yet).
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10819
diff changeset
53 ##
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
54 ## @item "spline"
12175
2090995ca588 Correct en-dash,em-dash instances in docstrings.
Rik <octave@nomad.inbox5.com>
parents: 11587
diff changeset
55 ## Cubic spline interpolation---smooth first and second derivatives
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
56 ## throughout the curve.
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
57 ## @end table
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
58 ##
14359
7277fe922e99 doc: Use Octave preference for double quote in docstrings in scripts/
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
59 ## The default method is "linear".
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
60 ##
8116
6c69f5cda32b For for extrapval in interpn
Kris Thielemans
parents: 7671
diff changeset
61 ## If @var{extrapval} is the scalar value, use it to replace the values
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
62 ## beyond the endpoints with that number. If @var{extrapval} is missing,
8116
6c69f5cda32b For for extrapval in interpn
Kris Thielemans
parents: 7671
diff changeset
63 ## assume NA.
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
64 ## @seealso{interp1, interp2, spline, ndgrid}
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
65 ## @end deftypefn
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
66
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
67 function vi = interpn (varargin)
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
68
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
69 method = "linear";
6742
ebf96cc00ee9 [project @ 2007-06-18 16:27:52 by jwe]
jwe
parents: 6722
diff changeset
70 extrapval = NA;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
71 nargs = nargin;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
72
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
73 if (nargin < 1 || ! isnumeric (varargin{1}))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
74 print_usage ();
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
75 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
76
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
77 if (ischar (varargin{end}))
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
78 method = varargin{end};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
79 nargs = nargs - 1;
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
80 elseif (nargs > 1 && ischar (varargin{end - 1}))
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
81 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end}))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
82 error ("interpn: extrapal is expected to be a numeric scalar");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
83 endif
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
84 method = varargin{end - 1};
8116
6c69f5cda32b For for extrapval in interpn
Kris Thielemans
parents: 7671
diff changeset
85 extrapval = varargin{end};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
86 nargs = nargs - 2;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
87 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
88
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
89 if (nargs < 3)
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
90 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
91 m = 1;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
92 if (nargs == 2)
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
93 if (ischar (varargin{2}))
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
94 method = varargin{2};
13161
6b6d0e51bd2f scripts/general/interpn.m: fix(m)==m is faster than round(m)==m
Ben Abbott <bpabbott@mac.com>
parents: 13151
diff changeset
95 elseif (isnumeric (m) && isscalar (m) && fix (m) == m)
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
96 m = varargin{2};
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
97 else
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
98 print_usage ();
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
99 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
100 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
101 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
102 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
103 x = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
104 y = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
105 for i = 1 : nd;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
106 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
107 y{i} = 1 : (1 / (2 ^ m)) : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
108 endfor
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
109 y{1} = y{1}.';
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
110 [y{:}] = ndgrid (y{:});
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
111 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1))
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
112 v = varargin{1};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
113 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
114 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
115 x = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
116 y = varargin (2 : nargs);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
117 for i = 1 : nd;
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
118 x{i} = 1 : sz(i);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
119 endfor
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
120 elseif (rem (nargs, 2) == 1 && nargs ==
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
121 (2 * ndims (varargin{ceil (nargs / 2)})) + 1)
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
122 nv = ceil (nargs / 2);
7208
a730e47fda4d [project @ 2007-11-28 02:32:41 by jwe]
jwe
parents: 7016
diff changeset
123 v = varargin{nv};
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
124 sz = size (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
125 nd = ndims (v);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
126 x = varargin (1 : (nv - 1));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
127 y = varargin ((nv + 1) : nargs);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
128 else
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
129 error ("interpn: wrong number or incorrectly formatted input arguments");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
130 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
131
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
132 if (any (! cellfun ("isvector", x)))
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
133 for i = 2 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
134 if (! size_equal (x{1}, x{i}) || ! size_equal (x{i}, v))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
135 error ("interpn: dimensional mismatch");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
136 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
137 idx (1 : nd) = {1};
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
138 idx (i) = ":";
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
139 x{i} = x{i}(idx{:})(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
140 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
141 idx (1 : nd) = {1};
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
142 idx (1) = ":";
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
143 x{1} = x{1}(idx{:})(:);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
144 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
145
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
146 method = tolower (method);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
147
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
148 all_vectors = all (cellfun ("isvector", y));
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
149 different_lengths = numel (unique (cellfun ("numel", y))) > 1;
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
150 if (all_vectors && different_lengths)
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
151 [foobar(1:numel(y)).y] = ndgrid (y{:});
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
152 y = {foobar.y};
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
153 endif
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
154
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
155 if (strcmp (method, "linear"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
156 vi = __lin_interpn__ (x{:}, v, y{:});
6742
ebf96cc00ee9 [project @ 2007-06-18 16:27:52 by jwe]
jwe
parents: 6722
diff changeset
157 vi (isna (vi)) = extrapval;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
158 elseif (strcmp (method, "nearest"))
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
159 yshape = size (y{1});
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
160 yidx = cell (1, nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
161 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
162 y{i} = y{i}(:);
7671
4fbaba9abec1 implement compiled binary lookup
Jaroslav Hajek <highegg@gmail.com>
parents: 7561
diff changeset
163 yidx{i} = lookup (x{i}, y{i}, "lr");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
164 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
165 idx = cell (1,nd);
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
166 for i = 1 : nd
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
167 idx{i} = yidx{i} + (y{i} - x{i}(yidx{i})(:) >= x{i}(yidx{i} + 1)(:) - y{i});
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
168 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
169 vi = v (sub2ind (sz, idx{:}));
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
170 idx = zeros (prod (yshape), 1);
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
171 for i = 1 : nd
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
172 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:));
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
173 endfor
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
174 vi(idx) = extrapval;
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
175 vi = reshape (vi, yshape);
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
176 elseif (strcmp (method, "spline"))
12931
cefd568ea073 Replace function handles with function names in cellfun calls for 15% speedup.
Rik <octave@nomad.inbox5.com>
parents: 12175
diff changeset
177 if (any (! cellfun ("isvector", y)))
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
178 for i = 2 : nd
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
179 if (! size_equal (y{1}, y{i}))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
180 error ("interpn: dimensional mismatch");
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
181 endif
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
182 idx (1 : nd) = {1};
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
183 idx (i) = ":";
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
184 y{i} = y{i}(idx{:});
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
185 endfor
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
186 idx (1 : nd) = {1};
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
187 idx (1) = ":";
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
188 y{1} = y{1}(idx{:});
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
189 endif
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
190
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
191 vi = __splinen__ (x, v, y, extrapval, "interpn");
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
192
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
193 if (size_equal (y{:}))
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
194 ly = length (y{1});
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
195 idx = cell (1, ly);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
196 q = cell (1, nd);
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
197 for i = 1 : ly
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
198 q(:) = i;
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10427
diff changeset
199 idx {i} = q;
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
200 endfor
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
201 vi = vi (cellfun (@(x) sub2ind (size(vi), x{:}), idx));
7424
132647e6c829 [project @ 2008-01-27 21:17:08 by dbateman]
dbateman
parents: 7423
diff changeset
202 vi = reshape (vi, size(y{1}));
7423
342a48abed2a [project @ 2008-01-25 23:54:47 by dbateman]
dbateman
parents: 7421
diff changeset
203 endif
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
204 elseif (strcmp (method, "cubic"))
10635
d1978e7364ad Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents: 10549
diff changeset
205 error ("interpn: cubic interpolation not yet implemented");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
206 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: 10846
diff changeset
207 error ("interpn: unrecognized interpolation METHOD");
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
208 endif
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
209
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
210 endfunction
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
211
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
212
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
213 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
214 %! clf;
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
215 %! 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
216 %! 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
217 %! 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
218 %! 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
219 %! 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
220 %! mesh (xi, yi, interpn (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
221 %! [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
222 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
223
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
224 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
225 %! clf;
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
226 %! 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
227 %! 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
228 %! 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
229 %! 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
230 %! 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
231 %! mesh (xi, yi, interpn (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
232 %! [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
233 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
234
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
235 %!#demo # FIXME: Uncomment when support for "cubic" has been added
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
236 %! clf;
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
237 %! 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
238 %! 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
239 %! 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
240 %! 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
241 %! 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
242 %! mesh (xi, yi, interpn (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
243 %! [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
244 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6702
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
245
b2391d403ed2 [project @ 2007-06-12 21:39:26 by dbateman]
dbateman
parents:
diff changeset
246 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
247 %! clf;
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
248 %! 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
249 %! 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
250 %! 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
251 %! 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
252 %! 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
253 %! mesh (xi, yi, interpn (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
254 %! [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
255 %! hold on; plot3 (x(:),y(:),A(:),"b*"); hold off;
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
256
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
257 %!demo
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
258 %! clf;
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
259 %! colormap ("default");
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
260 %! x = y = z = -1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
261 %! f = @(x,y,z) x.^2 - y - z.^2;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
262 %! [xx, yy, zz] = meshgrid (x, y, z);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
263 %! v = f (xx,yy,zz);
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
264 %! xi = yi = zi = -1:0.1:1;
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
265 %! [xxi, yyi, zzi] = ndgrid (xi, yi, zi);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14359
diff changeset
266 %! vi = interpn (x, y, z, v, xxi, yyi, zzi, "spline");
6721
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
267 %! mesh (yi, zi, squeeze (vi(1,:,:)));
01036667884a [project @ 2007-06-14 06:56:41 by dbateman]
dbateman
parents: 6702
diff changeset
268
7421
1c7b3e1fda19 [project @ 2008-01-25 21:00:42 by dbateman]
dbateman
parents: 7208
diff changeset
269 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
270 %! [x,y,z] = ndgrid (0:2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
271 %! f = x + y + z;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
272 %! assert (interpn (x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5]), [1.5, 4.5]);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
273 %! assert (interpn (x,y,z,f,[.51 1.51],[.51 1.51],[.51 1.51],"nearest"), [3, 6]);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
274 %! assert (interpn (x,y,z,f,[.5 1.5],[.5 1.5],[.5 1.5],"spline"), [1.5, 4.5]);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
275 %! assert (interpn (x,y,z,f,x,y,z), f);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
276 %! assert (interpn (x,y,z,f,x,y,z,"nearest"), f);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
277 %! assert (interpn (x,y,z,f,x,y,z,"spline"), f);
7561
a938cd7869b2 __lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents: 7424
diff changeset
278
a938cd7869b2 __lin_interpn__.cc: handle decreasing coordinate values
Alexander Barth
parents: 7424
diff changeset
279 %!test
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
280 %! [x, y, z] = ndgrid (0:2, 1:4, 2:6);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
281 %! f = x + y + z;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
282 %! xi = [0.5 1.0 1.5]; yi = [1.5 2.0 2.5 3.5]; zi = [2.5 3.5 4.0 5.0 5.5];
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
283 %! fi = interpn (x, y, z, f, xi, yi, zi);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
284 %! [xi, yi, zi] = ndgrid (xi, yi, zi);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
285 %! assert (fi, xi + yi + zi);
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
286
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
287 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
288 %! xi = 0:2; yi = 1:4; zi = 2:6;
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
289 %! [x, y, z] = ndgrid (xi, yi, zi);
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
290 %! f = x + y + z;
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
291 %! fi = interpn (x, y, z, f, xi, yi, zi, "nearest");
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
292 %! assert (fi, x + y + z);
10819
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
293
f3c984d45dcb interpn.m: Convert interpolation vectors of non-equal length to nd-arrays.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
294 %!test
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
295 %! [x,y,z] = ndgrid (0:2);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
296 %! f = x.^2 + y.^2 + z.^2;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
297 %! assert (interpn (x,y,-z,f,1.5,1.5,-1.5), 7.5);
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: 9245
diff changeset
298
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
299 %!test # for Matlab-compatible rounding for "nearest"
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
300 %! x = meshgrid (1:4);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
301 %! assert (interpn (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: 9245
diff changeset
302
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
303 %!test
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
304 %! z = zeros (3, 3, 3);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
305 %! zout = zeros (5, 5, 5);
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
306 %! z(:,:,1) = [1 3 5; 3 5 7; 5 7 9];
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
307 %! z(:,:,2) = z(:,:,1) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
308 %! z(:,:,3) = z(:,:,2) + 2;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
309 %! for n = 1:5
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
310 %! zout(:,:,n) = [1 2 3 4 5;
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
311 %! 2 3 4 5 6;
13151
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
312 %! 3 4 5 6 7;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
313 %! 4 5 6 7 8;
e173fda06fca Fix bug #30295.
Ben Abbott <bpabbott@mac.com>
parents: 12175
diff changeset
314 %! 5 6 7 8 9] + (n-1);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
315 %! endfor
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
316 %! tol = 10*eps;
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
317 %! assert (interpn (z), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
318 %! assert (interpn (z, "linear"), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
319 %! assert (interpn (z, "spline"), zout, tol);
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
320