Mercurial > octave-nkf
annotate scripts/geometry/griddata.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 | 5d3a684236b0 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11588
diff
changeset
|
1 ## Copyright (C) 1999-2012 Kai Habel |
6823 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6823 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6823 | 18 |
19 ## -*- texinfo -*- | |
14372
3f6489feca1e
griddata.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents:
14368
diff
changeset
|
20 ## @deftypefn {Function File} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}) |
3f6489feca1e
griddata.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents:
14368
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}, @var{method}) |
3f6489feca1e
griddata.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents:
14368
diff
changeset
|
22 ## @deftypefnx {Function File} {[@var{xi}, @var{yi}, @var{zi}] =} griddata (@dots{}) |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
23 ## |
6823 | 24 ## Generate a regular mesh from irregular data using interpolation. |
25 ## The function is defined by @code{@var{z} = f (@var{x}, @var{y})}. | |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
26 ## Inputs @code{@var{x}, @var{y}, @var{z}} are vectors of the same length |
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
27 ## or @code{@var{x}, @var{y}} are vectors and @code{@var{z}} is matrix. |
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
28 ## |
6823 | 29 ## The interpolation points are all @code{(@var{xi}, @var{yi})}. If |
11563
3c6e8aaa9555
Grammarcheck m-files before 3.4 release.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
30 ## @var{xi}, @var{yi} are vectors then they are made into a 2-D mesh. |
6823 | 31 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
32 ## The interpolation method can be @qcode{"nearest"}, @qcode{"cubic"} or |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14868
diff
changeset
|
33 ## @qcode{"linear"}. If method is omitted it defaults to @qcode{"linear"}. |
14372
3f6489feca1e
griddata.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents:
14368
diff
changeset
|
34 ## @seealso{griddata3, griddatan, delaunay} |
6823 | 35 ## @end deftypefn |
36 | |
10549 | 37 ## Author: Kai Habel <kai.habel@gmx.de> |
6823 | 38 ## Adapted-by: Alexander Barth <barth.alexander@gmail.com> |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
39 ## xi and yi are not "meshgridded" if both are vectors |
6823 | 40 ## of the same size (for compatibility) |
41 | |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
42 function [rx, ry, rz] = griddata (x, y, z, xi, yi, method = "linear") |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
43 |
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
44 if (nargin < 5 || nargin > 7) |
6826 | 45 print_usage (); |
6823 | 46 endif |
47 | |
6826 | 48 if (ischar (method)) |
49 method = tolower (method); | |
6823 | 50 endif |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
51 |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
52 ## Meshgrid if x and y are vectors but z is matrix |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
53 if (isvector (x) && isvector (y) && all ([numel(y), numel(x)] == size (z))) |
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
54 [x, y] = meshgrid (x, y); |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
55 endif |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
56 |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
57 if (isvector (x) && isvector (y) && isvector (z)) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
58 if (! isequal (length (x), length (y), length (z))) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
59 error ("griddata: X, Y, and Z must be vectors of the same length"); |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
60 endif |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
61 elseif (! size_equal (x, y, z)) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
62 error ("griddata: lengths of X, Y must match the columns and rows of Z"); |
6823 | 63 endif |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
64 |
9677
8cf522ce9c4d
fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
9501
diff
changeset
|
65 ## Meshgrid xi and yi if they are a row and column vector. |
8cf522ce9c4d
fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
9501
diff
changeset
|
66 if (rows (xi) == 1 && columns (yi) == 1) |
6826 | 67 [xi, yi] = meshgrid (xi, yi); |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
68 elseif (isvector (xi) && isvector (yi)) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
69 ## Otherwise, convert to column vectors |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
70 xi = xi(:); |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
71 yi = yi(:); |
6823 | 72 endif |
73 | |
9677
8cf522ce9c4d
fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
9501
diff
changeset
|
74 if (! 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:
10945
diff
changeset
|
75 error ("griddata: XI and YI must be vectors or matrices of same size"); |
6823 | 76 endif |
77 | |
9501 | 78 x = x(:); |
79 y = y(:); | |
80 z = z(:); | |
9495 | 81 |
8507 | 82 ## Triangulate data. |
6826 | 83 tri = delaunay (x, y); |
10548
479536c5bb10
Replace lowercase nan with NaN for visual cue in scripts
Rik <code@nomad.inbox5.com>
parents:
9677
diff
changeset
|
84 zi = NaN (size (xi)); |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
85 |
6826 | 86 if (strcmp (method, "cubic")) |
8664 | 87 error ("griddata: cubic interpolation not yet implemented"); |
6823 | 88 |
6826 | 89 elseif (strcmp (method, "nearest")) |
8507 | 90 ## Search index of nearest point. |
6826 | 91 idx = dsearch (x, y, tri, xi, yi); |
92 valid = !isnan (idx); | |
6823 | 93 zi(valid) = z(idx(valid)); |
94 | |
6826 | 95 elseif (strcmp (method, "linear")) |
8507 | 96 ## Search for every point the enclosing triangle. |
97 tri_list = tsearch (x, y, tri, xi(:), yi(:)); | |
6823 | 98 |
8507 | 99 ## Only keep the points within triangles. |
9496 | 100 valid = !isnan (tri_list); |
101 tri_list = tri_list(valid); | |
6826 | 102 nr_t = rows (tri_list); |
6823 | 103 |
9496 | 104 tri = tri(tri_list,:); |
105 | |
8507 | 106 ## Assign x,y,z for each point of triangle. |
9496 | 107 x1 = x(tri(:,1)); |
108 x2 = x(tri(:,2)); | |
109 x3 = x(tri(:,3)); | |
6826 | 110 |
9496 | 111 y1 = y(tri(:,1)); |
112 y2 = y(tri(:,2)); | |
113 y3 = y(tri(:,3)); | |
6826 | 114 |
9496 | 115 z1 = z(tri(:,1)); |
116 z2 = z(tri(:,2)); | |
117 z3 = z(tri(:,3)); | |
6823 | 118 |
8507 | 119 ## Calculate norm vector. |
6826 | 120 N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]); |
9496 | 121 ## Normalize. |
122 N = diag (norm (N, "rows")) \ N; | |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
123 |
8507 | 124 ## Calculate D of plane equation |
125 ## Ax+By+Cz+D = 0; | |
6823 | 126 D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1); |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
127 |
8507 | 128 ## Calculate zi by solving plane equation for xi, yi. |
9677
8cf522ce9c4d
fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents:
9501
diff
changeset
|
129 zi(valid) = -(N(:,1).*xi(:)(valid) + N(:,2).*yi(:)(valid) + D) ./ N(:,3); |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
130 |
6823 | 131 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:
10945
diff
changeset
|
132 error ("griddata: unknown interpolation METHOD"); |
6823 | 133 endif |
134 | |
6826 | 135 if (nargout == 3) |
6823 | 136 rx = xi; |
137 ry = yi; | |
138 rz = zi; | |
6826 | 139 elseif (nargout == 1) |
6823 | 140 rx = zi; |
6826 | 141 elseif (nargout == 0) |
142 mesh (xi, yi, zi); | |
6823 | 143 endif |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
144 |
6823 | 145 endfunction |
146 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
147 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
148 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
149 %! 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
|
150 %! 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
|
151 %! x = 2*rand (100,1) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
152 %! y = 2*rand (size (x)) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
153 %! z = sin (2*(x.^2 + y.^2)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
154 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
155 %! griddata (x,y,z,xx,yy); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
156 %! title ("nonuniform grid sampled at 100 points"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
157 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
158 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
159 %! 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
|
160 %! 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
|
161 %! x = 2*rand (1000,1) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
162 %! y = 2*rand (size (x)) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
163 %! z = sin (2*(x.^2 + y.^2)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
164 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
165 %! griddata (x,y,z,xx,yy); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
166 %! title ("nonuniform grid sampled at 1000 points"); |
6823 | 167 |
168 %!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
|
169 %! 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
|
170 %! 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
|
171 %! x = 2*rand (1000,1) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
172 %! y = 2*rand (size (x)) - 1; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
173 %! z = sin (2*(x.^2 + y.^2)); |
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
|
174 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
175 %! griddata (x,y,z,xx,yy,"nearest"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
176 %! title ("nonuniform grid sampled at 1000 points with nearest neighbor"); |
6823 | 177 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
178 %!testif HAVE_QHULL |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
179 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
180 %! x = xx(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
181 %! x = x + 10*(2*round (rand (size (x))) - 1) * eps; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
182 %! y = yy(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
183 %! y = y + 10*(2*round (rand (size (y))) - 1) * eps; |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
184 %! z = sin (2*(x.^2 + y.^2)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
185 %! zz = griddata (x,y,z,xx,yy,"linear"); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
186 %! zz2 = sin (2*(xx.^2 + yy.^2)); |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
187 %! zz2(isnan (zz)) = NaN; |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
188 %! assert (zz, zz2, 100*eps); |
6823 | 189 |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
190 %% Test input validation |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
191 %!error griddata () |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
192 %!error griddata (1) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
193 %!error griddata (1,2) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
194 %!error griddata (1,2,3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
195 %!error griddata (1,2,3,4) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
196 %!error griddata (1,2,3,4,5,6,7) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
197 %!error <vectors of the same length> griddata (1:3, 1:3, 1:4, 1:3, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
198 %!error <vectors of the same length> griddata (1:3, 1:4, 1:3, 1:3, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
199 %!error <vectors of the same length> griddata (1:4, 1:3, 1:3, 1:3, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
200 %!error <the columns and rows of Z> griddata (1:4, 1:3, ones (4,4), 1:3, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
201 %!error <the columns and rows of Z> griddata (1:4, 1:3, ones (3,5), 1:3, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
202 %!error <matrices of same size> griddata (1:3, 1:3, 1:3, 1:4, 1:3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
203 %!error <matrices of same size> griddata (1:3, 1:3, 1:3, 1:3, 1:4) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
204 |