annotate scripts/geometry/griddata.m @ 20595:c1a6c31ac29a

eliminate more simple uses of error_state * ov-classdef.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Oct 2015 00:20:02 -0400
parents 561af1ab6099
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19627
diff changeset
1 ## Copyright (C) 1999-2015 Kai Habel
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
2 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
3 ## This file is part of Octave.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
4 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
9fddcc586065 [project @ 2007-08-24 08:27:27 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: 6826
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: 6826
diff changeset
8 ## your option) any later version.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
9 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
13 ## General Public License for more details.
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
14 ##
9fddcc586065 [project @ 2007-08-24 08:27:27 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: 6826
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: 6826
diff changeset
17 ## <http://www.gnu.org/licenses/>.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
18
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
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
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
24 ## Generate a regular mesh from irregular data using interpolation.
10945
aa40bdbfa478 griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
25 ##
20193
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
26 ## The function is defined by @code{@var{z} = f (@var{x}, @var{y})}. Inputs
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
27 ## @code{@var{x}, @var{y}, @var{z}} are vectors of the same length or
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
28 ## @code{@var{x}, @var{y}} are vectors and @code{@var{z}} is matrix.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
29 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
30 ## The interpolation points are all @code{(@var{xi}, @var{yi})}. If @var{xi},
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19867
diff changeset
31 ## @var{yi} are vectors then they are made into a 2-D mesh.
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
32 ##
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 14868
diff changeset
33 ## 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
34 ## @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
35 ## @seealso{griddata3, griddatan, delaunay}
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
36 ## @end deftypefn
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
37
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10548
diff changeset
38 ## Author: Kai Habel <kai.habel@gmx.de>
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
39 ## 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
40 ## xi and yi are not "meshgridded" if both are vectors
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
41 ## of the same size (for compatibility)
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
42
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
43 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
44
aa40bdbfa478 griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents: 10793
diff changeset
45 if (nargin < 5 || nargin > 7)
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
46 print_usage ();
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
47 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
48
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
49 if (ischar (method))
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
50 method = tolower (method);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
51 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
52
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
53 ## 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
54 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
55 [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
56 endif
19627
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
57
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
58 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
59 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
60 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
61 endif
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
62 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
63 error ("griddata: lengths of X, Y must match the columns and rows of Z");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
64 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
65
9677
8cf522ce9c4d fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 9501
diff changeset
66 ## 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
67 if (rows (xi) == 1 && columns (yi) == 1)
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
68 [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
69 elseif (isvector (xi) && isvector (yi))
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
70 ## Otherwise, convert to column vectors
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
71 xi = xi(:);
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
72 yi = yi(:);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
73 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
74
9677
8cf522ce9c4d fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 9501
diff changeset
75 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
76 error ("griddata: XI and YI must be vectors or matrices of same size");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
77 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
78
9501
3c40d81c197f ChangeLog and style fixes
John W. Eaton <jwe@octave.org>
parents: 9496
diff changeset
79 x = x(:);
3c40d81c197f ChangeLog and style fixes
John W. Eaton <jwe@octave.org>
parents: 9496
diff changeset
80 y = y(:);
3c40d81c197f ChangeLog and style fixes
John W. Eaton <jwe@octave.org>
parents: 9496
diff changeset
81 z = z(:);
9495
0a427d3244bf fix griddata
Olaf Till <olaf.till@uni-jena.de>
parents: 8920
diff changeset
82
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
83 ## Triangulate data.
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
84 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
85 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
86
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
87 if (strcmp (method, "cubic"))
8664
e07e93c04080 style fixes
John W. Eaton <jwe@octave.org>
parents: 8507
diff changeset
88 error ("griddata: cubic interpolation not yet implemented");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
89
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
90 elseif (strcmp (method, "nearest"))
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
91 ## Search index of nearest point.
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
92 idx = dsearch (x, y, tri, xi, yi);
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
93 valid = ! isnan (idx);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
94 zi(valid) = z(idx(valid));
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
95
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
96 elseif (strcmp (method, "linear"))
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
97 ## Search for every point the enclosing triangle.
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
98 tri_list = tsearch (x, y, tri, xi(:), yi(:));
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
99
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
100 ## Only keep the points within triangles.
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
101 valid = ! isnan (tri_list);
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
102 tri_list = tri_list(valid);
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
103 nr_t = rows (tri_list);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
104
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
105 tri = tri(tri_list,:);
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
106
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
107 ## Assign x,y,z for each point of triangle.
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
108 x1 = x(tri(:,1));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
109 x2 = x(tri(:,2));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
110 x3 = x(tri(:,3));
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
111
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
112 y1 = y(tri(:,1));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
113 y2 = y(tri(:,2));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
114 y3 = y(tri(:,3));
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
115
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
116 z1 = z(tri(:,1));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
117 z2 = z(tri(:,2));
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
118 z3 = z(tri(:,3));
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
119
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
120 ## Calculate norm vector.
6826
8618f29520c6 [project @ 2007-08-24 16:02:07 by jwe]
jwe
parents: 6823
diff changeset
121 N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]);
9496
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
122 ## Normalize.
079c06f37f17 optimize griddata
Jaroslav Hajek <highegg@gmail.com>
parents: 9495
diff changeset
123 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
124
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
125 ## Calculate D of plane equation
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
126 ## Ax+By+Cz+D = 0;
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
127 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
128
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8153
diff changeset
129 ## Calculate zi by solving plane equation for xi, yi.
9677
8cf522ce9c4d fix griddata with vectors
Jaroslav Hajek <highegg@gmail.com>
parents: 9501
diff changeset
130 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
131
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
132 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
133 error ("griddata: unknown interpolation METHOD");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
134 endif
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
135
20249
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
136 if (nargout > 1)
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
137 rx = xi;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
138 ry = yi;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
139 rz = zi;
20249
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
140 else
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
141 rx = zi;
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
142 endif
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
143
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
144 endfunction
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
145
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
146
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
147 %!demo
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
148 %! 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
149 %! 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
150 %! 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
151 %! 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
152 %! 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
153 %! [xx,yy] = meshgrid (linspace (-1,1,32));
20249
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
154 %! zz = griddata (x,y,z,xx,yy);
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
155 %! mesh (xx, yy, zz);
14237
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));
20249
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
165 %! zz = griddata (x,y,z,xx,yy);
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
166 %! mesh (xx, yy, zz);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
167 %! title ("nonuniform grid sampled at 1000 points");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
168
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
169 %!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
170 %! 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
171 %! 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
172 %! 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
173 %! 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
174 %! 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
175 %! [xx,yy] = meshgrid (linspace (-1,1,32));
20249
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
176 %! zz = griddata (x,y,z,xx,yy,"nearest");
561af1ab6099 griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents: 20193
diff changeset
177 %! mesh (xx, yy, zz);
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 %! title ("nonuniform grid sampled at 1000 points with nearest neighbor");
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
179
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
180 %!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
181 %! [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
182 %! x = xx(:);
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14372
diff changeset
183 %! 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
184 %! y = yy(:);
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14372
diff changeset
185 %! 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
186 %! 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
187 %! 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
188 %! 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
189 %! 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
190 %! assert (zz, zz2, 100*eps);
6823
9fddcc586065 [project @ 2007-08-24 08:27:27 by dbateman]
dbateman
parents:
diff changeset
191
19867
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19731
diff changeset
192 ## Test input validation
14368
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
193 %!error griddata ()
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
194 %!error griddata (1)
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
195 %!error griddata (1,2)
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)
5736d93b22d0 griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents: 14247
diff changeset
197 %!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
198 %!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
199 %!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
200 %!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
201 %!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
202 %!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
203 %!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
204 %!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
205 %!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
206