Mercurial > octave
annotate scripts/geometry/griddata.m @ 28214:0e0e0de09f1e
griddata.m: Overhaul function.
* griddata.m: Rewrite documentation for clarity. Place all input validation
before calculations. Validate METHOD input more precisely. Don't calculate
Delaunay triangulation for "v4" method as it is unnecessary. Update BIST tests.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 13 Apr 2020 18:07:28 -0700 |
parents | bb929d5a34cb |
children | f5644ccd1df5 |
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"); | |
132 endif | |
133 method = tolower (method); | |
134 | |
135 if (any (strcmp (method, {"linear", "nearest", "v4"}))) | |
136 ## Do nothing, these are implemented methods | |
137 elseif (any (strcmp (method, {"cubic", "natural"}))) | |
138 ## FIXME: implement missing interpolation methods. | |
139 error ('griddata: "%s" interpolation not yet implemented', method); | |
140 else | |
141 error ('griddata: unknown interpolation METHOD: "%s"', method); | |
142 endif | |
143 else | |
144 method = "linear"; | |
145 endif | |
146 | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
147 x = x(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
148 y = y(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
149 z = z(:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
150 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
151 ## Triangulate data. |
28214 | 152 if (! strcmp (method, "v4")) |
153 tri = delaunay (x, y); | |
154 endif | |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
155 zi = NaN (size (xi)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
156 |
28214 | 157 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
|
158 ## 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
|
159 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
|
160 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
161 ## 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
|
162 valid = ! isnan (tri_list); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
163 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
|
164 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
|
165 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
166 tri = tri(tri_list,:); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
167 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
168 ## 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
|
169 x1 = x(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
170 x2 = x(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
171 x3 = x(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
172 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
173 y1 = y(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
174 y2 = y(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
175 y3 = y(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
176 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
177 z1 = z(tri(:,1)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
178 z2 = z(tri(:,2)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
179 z3 = z(tri(:,3)); |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
180 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
181 ## Calculate norm vector. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
182 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
|
183 ## Normalize. |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
184 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
|
185 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
186 ## 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
|
187 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
|
188 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
189 ## 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
|
190 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
|
191 |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
192 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
|
193 ## 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
|
194 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
|
195 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
|
196 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
|
197 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
198 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
|
199 ## 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
|
200 ## 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
|
201 ## 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
|
202 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
203 ## 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
|
204 ## 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
|
205 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
206 ## 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
|
207 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
208 ## 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
|
209 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
210 ## 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
|
211 ## |
28214 | 212 ## 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
|
213 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
214 ## 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
|
215 ## = 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
|
216 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
217 ## in which the coefficients alpha_j are the unknowns. rj is the |
28214 | 218 ## 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
|
219 ## 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
|
220 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
221 ## 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
|
222 ## = 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
|
223 ## |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
224 ## 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
|
225 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
226 ## Step1: Solve for weight coefficients alpha_j depending on the |
28214 | 227 ## Euclidean distances and the training data set {x,y,z} |
228 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
|
229 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
|
230 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
|
231 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
|
232 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
233 ## Step2 - Use alphas and Green's functions to get interpolated points. |
28214 | 234 ## Use dim3 projection for vectorized calculation to avoid loops. |
235 ## 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
|
236 ## 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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
245 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
246 |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
247 if (nargout > 1) |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
248 rx = xi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
249 ry = yi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
250 rz = zi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
251 else |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
252 rx = zi; |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
253 endif |
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
254 |
6823 | 255 endif |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
256 |
6823 | 257 endfunction |
258 | |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
259 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
260 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
261 %! 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
|
262 %! 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
|
263 %! 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
|
264 %! 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
|
265 %! 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
|
266 %! [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
|
267 %! 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
|
268 %! 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
|
269 %! 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
|
270 |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
271 %!demo |
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
272 %! 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
|
273 %! 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
|
274 %! 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
|
275 %! 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
|
276 %! 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
|
277 %! [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
|
278 %! 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
|
279 %! 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
|
280 %! 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
|
281 %! 'method = "linear"'}); |
6823 | 282 |
283 %!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
|
284 %! 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
|
285 %! 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
|
286 %! 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
|
287 %! 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
|
288 %! 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
|
289 %! [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
|
290 %! 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
|
291 %! 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
|
292 %! 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
|
293 %! 'method = "nearest neighbor"'}); |
6823 | 294 |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
295 %!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
|
296 %! [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
|
297 %! x = xx(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
298 %! 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
|
299 %! y = yy(:); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14372
diff
changeset
|
300 %! 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
|
301 %! 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
|
302 %! 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
|
303 %! 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
|
304 %! 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
|
305 %! assert (zz, zz2, 100*eps); |
6823 | 306 |
28210
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
307 %!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
|
308 %! [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
|
309 %! 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
|
310 %! 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
|
311 %! 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
|
312 %! 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
|
313 %! 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
|
314 %! 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
|
315 %! 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
|
316 %! 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
|
317 %! 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
|
318 |
bb929d5a34cb
griddata.m: Added support for "v4" biharmonic spline interpolation method (bug #33539).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28151
diff
changeset
|
319 %!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
|
320 %! [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
|
321 %! 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
|
322 %! 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
|
323 %! 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
|
324 %! 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
|
325 %! 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
|
326 %! 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
|
327 %! 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
|
328 %! 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
|
329 %! 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
|
330 |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
331 ## Test input validation |
14368
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
332 %!error griddata () |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
333 %!error griddata (1) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
334 %!error griddata (1,2) |
5736d93b22d0
griddata.m: Accept vectors in any orientation (Bug #33539)
Rik <octave@nomad.inbox5.com>
parents:
14247
diff
changeset
|
335 %!error griddata (1,2,3) |
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,4) |
28151
37ee7c5cc6b2
griddata.m: Add support for 3D inputs (bug #57323).
Nicholas R. Jankowski <jankowskin@asme.org>
parents:
28027
diff
changeset
|
337 %!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
|
338 %!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
|
339 %!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
|
340 %!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
|
341 %!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
|
342 %!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
|
343 %!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
|
344 %!error <XI and YI .* matrices of same size> griddata (1:3, 1:3, 1:3, 1:3, 1:4) |
28214 | 345 %!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
|
346 %!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
|
347 %!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
|
348 %!error <unknown interpolation METHOD: "foobar"> griddata (1,2,3,4,5, "foobar") |