Mercurial > octave
annotate scripts/geometry/griddata.m @ 28216:f5644ccd1df5
griddata.m, griddatan.m: Small tweak in input validation.
* griddata.m: Only call tolower on METHOD input when it is required.
* griddatan.m: Only call tolower on METHOD input when it is required.
Add note to documentation that query values outside the convex hull
will return NaN.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 13 Apr 2020 18:19:41 -0700 |
parents | 0e0e0de09f1e |
children | 90fea9cc9caa |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 ## Copyright (C) 1999-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27845
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
6823 | 7 ## |
8 ## This file is part of Octave. | |
9 ## | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
6823 | 11 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
6823 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
6823 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 21 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
6823 | 25 |
26 ## -*- texinfo -*- | |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20214
diff
changeset
|
27 ## @deftypefn {} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20214
diff
changeset
|
28 ## @deftypefnx {} {@var{zi} =} griddata (@var{x}, @var{y}, @var{z}, @var{xi}, @var{yi}, @var{method}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20214
diff
changeset
|
29 ## @deftypefnx {} {[@var{xi}, @var{yi}, @var{zi}] =} griddata (@dots{}) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
30 ## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
31 ## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
32 ## @deftypefnx {} {@var{vi} =} griddata (@var{x}, @var{y}, @var{z}, @var{v}, @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options}) |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
33 ## |
28214 | 34 ## Interpolate irregular 2-D and 3-D source data at specified points. |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
35 ## |
28214 | 36 ## For 2-D interpolation, the inputs @var{x} and @var{y} define the points |
37 ## where the function @code{@var{z} = f (@var{x}, @var{y})} is evaluated. | |
38 ## The inputs @var{x}, @var{y}, @var{z} are either vectors of the same length, | |
39 ## or the unequal vectors @var{x}, @var{y} are expanded to a 2-D grid with | |
40 ## @code{meshgrid} and @var{z} is a 2-D matrix matching the resulting size of | |
41 ## the X-Y grid. | |
42 ## | |
43 ## The interpolation points are (@var{xi}, @var{yi}). If, and only if, | |
44 ## @var{xi} is a row vector and @var{yi} is a column vector, then | |
45 ## @code{meshgrid} will be used to create a mesh of interpolation points. | |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
46 ## |
28214 | 47 ## For 3-D interpolation, the inputs @var{x}, @var{y}, and @var{z} define the |
48 ## points where the function @code{@var{v} = f (@var{x}, @var{y}, @var{z})} | |
49 ## is evaluated. The inputs @var{x}, @var{y}, @var{z} are either vectors of | |
50 ## the same length, or if they are of unequal length, then they are expanded to | |
51 ## a 3-D grid with @code{meshgrid}. The size of the input @var{v} must match | |
52 ## the size of the original data, either as a vector or a matrix. | |
6823 | 53 ## |
28214 | 54 ## The optional input interpolation @var{method} can be @qcode{"nearest"}, |
55 ## @qcode{"linear"}, or for 2-D data @qcode{"v4"}. When the method is | |
56 ## @qcode{"nearest"}, the output @var{vi} will be the closest point in the | |
57 ## original data (@var{x}, @var{y}, @var{z}) to the query point (@var{xi}, | |
58 ## @var{yi}, @var{zi}). When the method is @qcode{"linear"}, the output | |
59 ## @var{vi} will be a linear interpolation between the two closest points in | |
60 ## the original source data in each dimension. For 2-D cases only, the | |
61 ## @qcode{"v4"} method is also available which implements a biharmonic spline | |
62 ## interpolation. If @var{method} is omitted or empty, it defaults to | |
63 ## @qcode{"linear"}. | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
64 ## |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
65 ## For 3-D interpolation, the optional argument @var{options} is passed |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
66 ## directly to Qhull when computing the Delaunay triangulation used for |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
67 ## interpolation. See @code{delaunayn} for information on the defaults and |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
68 ## how to pass different values. |
28214 | 69 ## |
70 ## Programming Notes: If the input is complex the real and imaginary parts | |
71 ## are interpolated separately. Interpolation is normally based on a | |
72 ## Delaunay triangulation. Any query values outside the convex hull of the | |
73 ## input points will return @code{NaN}. However, the @qcode{"v4"} method does | |
74 ## not use the triangulation and will return values outside the original data | |
75 ## (extrapolation). | |
14372
3f6489feca1e
griddata.m: Update docstring.
Rik <octave@nomad.inbox5.com>
parents:
14368
diff
changeset
|
76 ## @seealso{griddata3, griddatan, delaunay} |
6823 | 77 ## @end deftypefn |
78 | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
79 function [rx, ry, rz] = griddata (x, y, z, varargin) |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
80 |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
81 if (nargin < 5) |
6826 | 82 print_usage (); |
6823 | 83 endif |
84 | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
85 if (nargin > 6) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
86 ## Current 2D implementation has nargin max = 6, since no triangulation |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
87 ## options are passed to the 2D algorithm. 3D algorithm requires nargin >=7 |
6823 | 88 |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
89 if (nargout > 1) |
28214 | 90 error ("griddata: only one output argument valid for 3-D interpolation"); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
91 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
92 rx = griddata3 (x, y, z, varargin{:}); |
10945
aa40bdbfa478
griddata.m: Allow x, y inputs to be vectors, and z a matrix.
Ben Abbott <bpabbott@mac.com>
parents:
10793
diff
changeset
|
93 |
6823 | 94 else |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
95 ## for nargin 5 or 6, assign varargin terms to variables for 2D algorithm |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
96 xi = varargin{1}; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
97 yi = varargin{2}; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
98 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
99 ## Meshgrid if x and y are vectors but z is matrix |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
100 if (isvector (x) && isvector (y) && all ([numel(y), numel(x)] == size (z))) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
101 [x, y] = meshgrid (x, y); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
102 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
103 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
104 if (isvector (x) && isvector (y) && isvector (z)) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
105 if (! isequal (length (x), length (y), length (z))) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
106 error ("griddata: X, Y, and Z must be vectors of the same length"); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
107 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
108 elseif (! size_equal (x, y, z)) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
109 error ("griddata: lengths of X, Y must match the columns and rows of Z"); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
110 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
111 |
28214 | 112 ## Meshgrid xi and yi if they are a row and column vector, but not |
113 ## if they are simply vectors of the same size (for compatibility). | |
114 if (isrow (xi) && iscolumn (yi)) | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
115 [xi, yi] = meshgrid (xi, yi); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
116 elseif (isvector (xi) && isvector (yi)) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
117 ## Otherwise, convert to column vectors |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
118 xi = xi(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
119 yi = yi(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
120 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
121 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
122 if (! size_equal (xi, yi)) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
123 error ("griddata: XI and YI must be vectors or matrices of same size"); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
124 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
125 |
28214 | 126 if (nargin == 6) |
127 method = varargin{3}; | |
128 if (isempty (method)) | |
129 method = "linear"; | |
130 elseif (! ischar (method)) | |
131 error ("griddata: METHOD must be a string"); | |
28216
f5644ccd1df5
griddata.m, griddatan.m: Small tweak in input validation.
Rik <rik@octave.org>
parents:
28214
diff
changeset
|
132 else |
f5644ccd1df5
griddata.m, griddatan.m: Small tweak in input validation.
Rik <rik@octave.org>
parents:
28214
diff
changeset
|
133 method = tolower (method); |
28214 | 134 endif |
135 | |
136 if (any (strcmp (method, {"linear", "nearest", "v4"}))) | |
137 ## Do nothing, these are implemented methods | |
138 elseif (any (strcmp (method, {"cubic", "natural"}))) | |
139 ## FIXME: implement missing interpolation methods. | |
140 error ('griddata: "%s" interpolation not yet implemented', method); | |
141 else | |
142 error ('griddata: unknown interpolation METHOD: "%s"', method); | |
143 endif | |
144 else | |
145 method = "linear"; | |
146 endif | |
147 | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
148 x = x(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
149 y = y(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
150 z = z(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
151 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
152 ## Triangulate data. |
28214 | 153 if (! strcmp (method, "v4")) |
154 tri = delaunay (x, y); | |
155 endif | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
156 zi = NaN (size (xi)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
157 |
28214 | 158 if (strcmp (method, "linear")) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
159 ## Search for every point the enclosing triangle. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
160 tri_list = tsearch (x, y, tri, xi(:), yi(:)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
161 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
162 ## Only keep the points within triangles. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
163 valid = ! isnan (tri_list); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
164 tri_list = tri_list(valid); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
165 nr_t = rows (tri_list); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
166 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
167 tri = tri(tri_list,:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
168 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
169 ## Assign x,y,z for each point of triangle. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
170 x1 = x(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
171 x2 = x(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
172 x3 = x(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
173 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
174 y1 = y(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
175 y2 = y(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
176 y3 = y(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
177 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
178 z1 = z(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
179 z2 = z(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
180 z3 = z(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
181 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
182 ## Calculate norm vector. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
183 N = cross ([x2-x1, y2-y1, z2-z1], [x3-x1, y3-y1, z3-z1]); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
184 ## Normalize. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
185 N = diag (norm (N, "rows")) \ N; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
186 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
187 ## Calculate D of plane equation: Ax+By+Cz+D = 0 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
188 D = -(N(:,1) .* x1 + N(:,2) .* y1 + N(:,3) .* z1); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
189 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
190 ## Calculate zi by solving plane equation for xi, yi. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
191 zi(valid) = -(N(:,1).*xi(:)(valid) + N(:,2).*yi(:)(valid) + D) ./ N(:,3); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
192 |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
193 elseif (strcmp (method, "nearest")) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
194 ## Search index of nearest point. |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
195 idx = dsearch (x, y, tri, xi, yi); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
196 valid = ! isnan (idx); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
197 zi(valid) = z(idx(valid)); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
198 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
199 elseif (strcmp (method, "v4")) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
200 ## Use Biharmonic Spline Interpolation Green's Function method. |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
201 ## Compatible with Matlab v4 interpolation method, based on |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
202 ## D. Sandwell 1987 and Deng & Tang 2011. |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
203 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
204 ## The free space Green Function which solves the two dimensional |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
205 ## Biharmonic PDE |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
206 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
207 ## Delta(Delta(G(X))) = delta(X) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
208 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
209 ## for a point source yields |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
210 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
211 ## G(X) = |X|^2 * (ln|X|-1) / (8 * pi) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
212 ## |
28214 | 213 ## An N-point Biharmonic Interpolation at the point X is given by |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
214 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
215 ## z(X) = sum_j_N (alpha_j * G(X-Xj)) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
216 ## = sum_j_N (alpha_j * G(rj)) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
217 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
218 ## in which the coefficients alpha_j are the unknowns. rj is the |
28214 | 219 ## Euclidean distance between X and Xj. |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
220 ## From N datapoints {zi, Xi} an equation system can be formed: |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
221 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
222 ## zi(Xi) = sum_j_N (alpha_j * G(Xi-Xj)) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
223 ## = sum_j_N (alpha_j * G(rij)) |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
224 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
225 ## Its inverse yields the unknowns alpha_j. |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
226 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
227 ## Step1: Solve for weight coefficients alpha_j depending on the |
28214 | 228 ## Euclidean distances and the training data set {x,y,z} |
229 r = sqrt ((x - x.').^2 + (y - y.').^2); # size N^2 | |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
230 D = (r.^2) .* (log (r) - 1); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
231 D(isnan (D)) = 0; # Fix Green Function for r=0 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
232 alpha_j = D \ z; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
233 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
234 ## Step2 - Use alphas and Green's functions to get interpolated points. |
28214 | 235 ## Use dim3 projection for vectorized calculation to avoid loops. |
236 ## Memory usage is proportional to Ni x N. | |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
237 ## FIXME: if this approach is too memory intensive, revert portion to loop |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
238 x = permute (x, [3, 2, 1]); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
239 y = permute (y, [3, 2, 1]); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
240 alpha_j = permute (alpha_j, [3, 2, 1]); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
241 r_i = sqrt ((xi - x).^2 + (yi - y).^2); # size Ni x N |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
242 Di = (r_i.^2) .* (log (r_i) - 1); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
243 Di(isnan (Di)) = 0; # Fix Green's Function for r==0 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
244 zi = sum (Di .* alpha_j, 3); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
245 |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
246 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
247 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
248 if (nargout > 1) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
249 rx = xi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
250 ry = yi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
251 rz = zi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
252 else |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
253 rx = zi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
254 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
255 |
6823 | 256 endif |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
257 |
6823 | 258 endfunction |
259 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
260 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
261 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
262 %! 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
|
263 %! 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
|
264 %! 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
|
265 %! 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
|
266 %! z = sin (2*(x.^2 + y.^2)); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
267 %! [xx,yy] = meshgrid (linspace (-1, 1, 32)); |
20214
561af1ab6099
griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents:
20158
diff
changeset
|
268 %! 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:
20158
diff
changeset
|
269 %! mesh (xx, yy, zz); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
270 %! title ("non-uniform grid sampled at 100 points"); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
271 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
272 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
273 %! 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
|
274 %! 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
|
275 %! 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
|
276 %! 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
|
277 %! z = sin (2*(x.^2 + y.^2)); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
278 %! [xx,yy] = meshgrid (linspace (-1, 1, 32)); |
20214
561af1ab6099
griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents:
20158
diff
changeset
|
279 %! 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:
20158
diff
changeset
|
280 %! mesh (xx, yy, zz); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
281 %! title ({"non-uniform grid sampled at 1,000 points", |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
282 %! 'method = "linear"'}); |
6823 | 283 |
284 %!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
|
285 %! 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
|
286 %! 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
|
287 %! 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
|
288 %! 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
|
289 %! z = sin (2*(x.^2 + y.^2)); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
290 %! [xx,yy] = meshgrid (linspace (-1, 1, 32)); |
20214
561af1ab6099
griddata.m: Return values instead of plotting for Matlab compatibility (bug #45125)
Mike Miller <mtmiller@octave.org>
parents:
20158
diff
changeset
|
291 %! 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:
20158
diff
changeset
|
292 %! mesh (xx, yy, zz); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
293 %! title ({"non-uniform grid sampled at 1,000 points", |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
294 %! 'method = "nearest neighbor"'}); |
6823 | 295 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
296 %!testif HAVE_QHULL |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
297 %! [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
|
298 %! x = xx(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
299 %! 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
|
300 %! y = yy(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
301 %! 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
|
302 %! z = sin (2*(x.^2 + y.^2)); |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
303 %! zz = griddata (x,y,z,xx,yy, "linear"); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
304 %! 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
|
305 %! 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
|
306 %! assert (zz, zz2, 100*eps); |
6823 | 307 |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
308 %!testif HAVE_QHULL |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
309 %! [xx, yy] = meshgrid (linspace (-1, 1, 5)); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
310 %! x = xx(:); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
311 %! x = x + 10*(2*round (rand (size (x))) - 1) * eps; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
312 %! y = yy(:); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
313 %! y = y + 10*(2*round (rand (size (y))) - 1) * eps; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
314 %! z = 2*(x.^2 + y.^2); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
315 %! zz = griddata (x,y,z,xx,yy, "v4"); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
316 %! zz2 = 2*(xx.^2 + yy.^2); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
317 %! zz2(isnan (zz)) = NaN; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
318 %! assert (zz, zz2, 100*eps); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
319 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
320 %!testif HAVE_QHULL |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
321 %! [xx, yy] = meshgrid (linspace (-1, 1, 5)); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
322 %! x = xx(:); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
323 %! x = x + 10*(2*round (rand (size (x))) - 1) * eps; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
324 %! y = yy(:); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
325 %! y = y + 10*(2*round (rand (size (y))) - 1) * eps; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
326 %! z = 2*(x.^2 + y.^2); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
327 %! zz = griddata (x,y,z,xx,yy, "nearest"); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
328 %! zz2 = 2*(xx.^2 + yy.^2); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
329 %! zz2(isnan (zz)) = NaN; |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
330 %! assert (zz, zz2, 100*eps); |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
331 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
332 ## Test input validation |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
333 %!error griddata () |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
334 %!error griddata (1) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
335 %!error griddata (1,2) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
336 %!error griddata (1,2,3) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
337 %!error griddata (1,2,3,4) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
338 %!error <only one output argument> [xi,yi] = griddata (1,2,3,4,5,6,7) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
339 %!error <vectors of the same length> griddata (1:4, 1:3, 1:3, 1:3, 1:3) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
340 %!error <vectors of the same length> griddata (1:3, 1:4, 1:3, 1:3, 1:3) |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
341 %!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
|
342 %!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
|
343 %!error <the columns and rows of Z> griddata (1:4, 1:3, ones (3,5), 1:3, 1:3) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
344 %!error <XI and YI .* matrices of same size> griddata (1:3, 1:3, 1:3, 1:4, 1:3) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
345 %!error <XI and YI .* matrices of same size> griddata (1:3, 1:3, 1:3, 1:3, 1:4) |
28214 | 346 %!error <METHOD must be a string> griddata (1,2,3,4,5, {"linear"}) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
347 %!error <"cubic" .* not yet implemented> griddata (1,2,3,4,5, "cubic") |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
348 %!error <"natural" .* not yet implemented> griddata (1,2,3,4,5, "natural") |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
349 %!error <unknown interpolation METHOD: "foobar"> griddata (1,2,3,4,5, "foobar") |