Mercurial > hg > octave-nkf
annotate scripts/geometry/griddata3.m @ 8362:03b414516dd8
clean up bzip2, gzip and __xzip__
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Sat, 29 Nov 2008 23:03:16 +0100 |
parents | ec0a13863eb7 |
children | eb63fbe60fab |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 2007 David Bateman |
6823 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
6823 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
6823 | 18 |
19 ## -*- texinfo -*- | |
20 ## @deftypefn {Function File} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v} @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options}) | |
21 ## | |
22 ## Generate a regular mesh from irregular data using interpolation. | |
23 ## The function is defined by @code{@var{y} = f (@var{x},@var{y},@var{z})}. | |
24 ## The interpolation points are all @var{xi}. | |
25 ## | |
6826 | 26 ## The interpolation method can be @code{"nearest"} or @code{"linear"}. |
27 ## If method is omitted it defaults to @code{"linear"}. | |
6823 | 28 ## @seealso{griddata, delaunayn} |
29 ## @end deftypefn | |
30 | |
7017 | 31 ## Author: David Bateman <dbateman@free.fr> |
32 | |
7585
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
33 function vi = griddata3 (x, y, z, v, xi, yi, zi, method, varargin) |
6823 | 34 |
6826 | 35 if (nargin < 7) |
36 print_usage (); | |
6823 | 37 endif |
38 | |
6826 | 39 if (!all (size (x) == size (y) & size (x) == size(z) & size(x) == size (v))) |
40 error ("griddata3: x, y, z, and v must be vectors of same length"); | |
6823 | 41 endif |
42 | |
43 ## meshgrid xi, yi and zi if they are vectors unless they | |
44 ## are vectors of the same length | |
6826 | 45 if (isvector (xi) && isvector (yi) && isvector (zi) |
46 && (numel (xi) != numel (yi) || numel (xi) != numel (zi))) | |
47 [xi, yi, zi] = meshgrid (xi, yi, zi); | |
6823 | 48 endif |
49 | |
6826 | 50 if (any (size(xi) != size(yi)) || any (size(xi) != size(zi))) |
7585
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
51 error ("griddata3: xi, yi and zi must be vectors or matrices of same size"); |
6823 | 52 endif |
53 | |
7585
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
54 vi = griddatan ([x(:), y(:), z(:)], v(:), [xi(:), yi(:), zi(:)], varargin{:}); |
6826 | 55 vi = reshape (vi, size (xi)); |
6823 | 56 endfunction |
57 | |
8153
ec0a13863eb7
Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents:
7585
diff
changeset
|
58 %!testif HAVE_QHULL |
7585
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
59 %! rand('state', 0); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
60 %! x = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
61 %! y = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
62 %! z = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
63 %! v = x.^2 + y.^2 + z.^2; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
64 %! [xi, yi, zi] = meshgrid (-0.8:0.2:0.8); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
65 %! ##vi = reshape (griddatan([x(:), y(:), z(:)], v, [xi(:), yi(:), zi(:)], 'linear'), size (xi)); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
66 %! vi = griddata3 (x, y, z, v, xi, yi, zi, 'linear'); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
67 %! vv = vi - xi.^2 - yi.^2 - zi.^2; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
68 %! assert (max(abs(vv(:))), 0, 0.1) |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
69 |
8153
ec0a13863eb7
Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents:
7585
diff
changeset
|
70 %!testif HAVE_QHULL |
7585
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
71 %! rand('state', 0); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
72 %! x = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
73 %! y = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
74 %! z = 2 * rand(1000, 1) - 1; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
75 %! v = x.^2 + y.^2 + z.^2; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
76 %! [xi, yi, zi] = meshgrid (-0.8:0.2:0.8); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
77 %! ##vi = reshape (griddatan([x(:), y(:), z(:)], v, [xi(:), yi(:), zi(:)], 'linear'), size (xi)); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
78 %! vi = griddata3 (x, y, z, v, xi, yi, zi, 'nearest'); |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
79 %! vv = vi - xi.^2 - yi.^2 - zi.^2; |
522433b05f45
Fix griddata3 and add test code
David Bateman <dbateman@free.fr>
parents:
7418
diff
changeset
|
80 %! assert (max(abs(vv(:))), 0, 0.1) |