Mercurial > octave-antonio
annotate scripts/geometry/griddatan.m @ 20158:7503499a252b stable
doc: Update docstrings to have one sentence summary as first line.
Update scripts in audio, elfun, general, geometry, and image directories.
* scripts/audio/@audioplayer/__get_properties__.m,
scripts/audio/@audioplayer/audioplayer.m, scripts/audio/@audioplayer/get.m,
scripts/audio/@audioplayer/isplaying.m, scripts/audio/@audioplayer/play.m,
scripts/audio/@audioplayer/playblocking.m, scripts/audio/@audioplayer/set.m,
scripts/audio/@audioplayer/subsasgn.m, scripts/audio/@audioplayer/subsref.m,
scripts/audio/@audiorecorder/audiorecorder.m,
scripts/audio/@audiorecorder/get.m,
scripts/audio/@audiorecorder/getaudiodata.m,
scripts/audio/@audiorecorder/getplayer.m,
scripts/audio/@audiorecorder/isrecording.m,
scripts/audio/@audiorecorder/play.m, scripts/audio/@audiorecorder/record.m,
scripts/audio/@audiorecorder/recordblocking.m,
scripts/audio/@audiorecorder/set.m, scripts/audio/@audiorecorder/stop.m,
scripts/audio/@audiorecorder/subsasgn.m,
scripts/audio/@audiorecorder/subsref.m, scripts/audio/lin2mu.m,
scripts/audio/mu2lin.m, scripts/audio/record.m, scripts/audio/sound.m,
scripts/audio/soundsc.m, scripts/audio/wavread.m, scripts/audio/wavwrite.m,
scripts/elfun/cosd.m, scripts/elfun/sind.m, scripts/elfun/tand.m,
scripts/general/accumarray.m, scripts/general/accumdim.m,
scripts/general/bitcmp.m, scripts/general/bitget.m, scripts/general/bitset.m,
scripts/general/blkdiag.m, scripts/general/cart2pol.m,
scripts/general/cart2sph.m, scripts/general/cell2mat.m,
scripts/general/celldisp.m, scripts/general/chop.m,
scripts/general/circshift.m, scripts/general/common_size.m,
scripts/general/cplxpair.m, scripts/general/cumtrapz.m,
scripts/general/dblquad.m, scripts/general/deal.m, scripts/general/del2.m,
scripts/general/display.m, scripts/general/divergence.m,
scripts/general/fieldnames.m, scripts/general/flip.m,
scripts/general/flipdim.m, scripts/general/fliplr.m, scripts/general/flipud.m,
scripts/general/gradient.m, scripts/general/interp3.m,
scripts/general/interpft.m, scripts/general/interpn.m,
scripts/general/loadobj.m, scripts/general/logspace.m,
scripts/general/methods.m, scripts/general/nargchk.m,
scripts/general/narginchk.m, scripts/general/nargoutchk.m,
scripts/general/nextpow2.m, scripts/general/nthargout.m,
scripts/general/num2str.m, scripts/general/pol2cart.m,
scripts/general/polyarea.m, scripts/general/postpad.m,
scripts/general/prepad.m, scripts/general/profile.m, scripts/general/quadgk.m,
scripts/general/quadl.m, scripts/general/quadv.m, scripts/general/randi.m,
scripts/general/rat.m, scripts/general/repmat.m, scripts/general/rot90.m,
scripts/general/rotdim.m, scripts/general/saveobj.m, scripts/general/shift.m,
scripts/general/shiftdim.m, scripts/general/sortrows.m,
scripts/general/sph2cart.m, scripts/general/structfun.m,
scripts/general/subsindex.m, scripts/general/trapz.m,
scripts/general/triplequad.m, scripts/geometry/delaunayn.m,
scripts/geometry/dsearch.m, scripts/geometry/dsearchn.m,
scripts/geometry/griddata.m, scripts/geometry/griddata3.m,
scripts/geometry/griddatan.m, scripts/geometry/inpolygon.m,
scripts/geometry/rectint.m, scripts/geometry/tsearchn.m,
scripts/geometry/voronoi.m, scripts/geometry/voronoin.m,
scripts/help/__unimplemented__.m, scripts/help/doc.m,
scripts/help/doc_cache_create.m, scripts/help/get_first_help_sentence.m,
scripts/help/help.m, scripts/help/lookfor.m, scripts/help/print_usage.m,
scripts/help/type.m, scripts/help/which.m, scripts/image/autumn.m,
scripts/image/bone.m, scripts/image/brighten.m, scripts/image/cmpermute.m,
scripts/image/colorcube.m, scripts/image/contrast.m, scripts/image/cool.m,
scripts/image/copper.m, scripts/image/cubehelix.m, scripts/image/flag.m,
scripts/image/gmap40.m, scripts/image/gray.m, scripts/image/gray2ind.m,
scripts/image/hot.m, scripts/image/hsv.m, scripts/image/image.m,
scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m,
scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m,
scripts/image/iscolormap.m, scripts/image/jet.m, scripts/image/lines.m,
scripts/image/ntsc2rgb.m, scripts/image/ocean.m, scripts/image/pink.m,
scripts/image/prism.m, scripts/image/rainbow.m, scripts/image/rgb2ntsc.m,
scripts/image/spinmap.m, scripts/image/spring.m, scripts/image/summer.m,
scripts/image/white.m, scripts/image/winter.m:
Update docstrings to have one sentence summary as first line.
Re-structure to have line lengths <= 80 chars.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 May 2015 09:36:20 -0700 |
parents | 9fc020886ae9 |
children |
rev | line source |
---|---|
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19593
diff
changeset
|
1 ## Copyright (C) 2007-2015 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 -*- | |
14370
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
20 ## @deftypefn {Function File} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}) |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
21 ## @deftypefnx {Function File} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}) |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}, @var{options}) |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
23 ## |
6823 | 24 ## Generate a regular mesh from irregular data using interpolation. |
20158
7503499a252b
doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19833
diff
changeset
|
25 ## |
6823 | 26 ## The function is defined by @code{@var{y} = f (@var{x})}. |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
27 ## The interpolation points are all @var{xi}. |
6823 | 28 ## |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14370
diff
changeset
|
29 ## The interpolation method can be @qcode{"nearest"} or @qcode{"linear"}. |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
14370
diff
changeset
|
30 ## If method is omitted it defaults to @qcode{"linear"}. |
19593
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
31 ## |
14370
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
32 ## The optional argument @var{options} is passed directly to Qhull when |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
33 ## computing the Delaunay triangulation used for interpolation. See |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
34 ## @code{delaunayn} for information on the defaults and how to pass different |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
35 ## values. |
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
36 ## @seealso{griddata, griddata3, delaunayn} |
6823 | 37 ## @end deftypefn |
38 | |
7017 | 39 ## Author: David Bateman <dbateman@free.fr> |
40 | |
14370
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
41 function yi = griddatan (x, y, xi, method = "linear", varargin) |
6826 | 42 |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
43 if (nargin < 3) |
6826 | 44 print_usage (); |
6823 | 45 endif |
46 | |
6826 | 47 if (ischar (method)) |
48 method = tolower (method); | |
6823 | 49 endif |
50 | |
6826 | 51 [m, n] = size (x); |
52 [mi, ni] = size (xi); | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 |
14370
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
54 if (n != ni || rows (y) != m || columns (y) != 1) |
6823 | 55 error ("griddatan: dimensional mismatch"); |
56 endif | |
57 | |
58 ## triangulate data | |
14370
fbdee844550c
griddatan.m: Restore ability to pass options to underlying Qhull
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
59 tri = delaunayn (x, varargin{:}); |
6823 | 60 |
10548
479536c5bb10
Replace lowercase nan with NaN for visual cue in scripts
Rik <code@nomad.inbox5.com>
parents:
8920
diff
changeset
|
61 yi = NaN (mi, 1); |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
62 |
6826 | 63 if (strcmp (method, "nearest")) |
6823 | 64 ## search index of nearest point |
6826 | 65 idx = dsearchn (x, tri, xi); |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
66 valid = ! isnan (idx); |
6823 | 67 yi(valid) = y(idx(valid)); |
68 | |
6826 | 69 elseif (strcmp (method, "linear")) |
6823 | 70 ## search for every point the enclosing triangle |
6826 | 71 [tri_list, bary_list] = tsearchn (x, tri, xi); |
6823 | 72 |
73 ## only keep the points within triangles. | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
74 valid = ! isnan (tri_list); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
75 tri_list = tri_list(! isnan (tri_list)); |
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
76 bary_list = bary_list(! isnan (tri_list), :); |
6826 | 77 nr_t = rows (tri_list); |
6823 | 78 |
79 ## assign x,y for each point of simplex | |
19833
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
80 xt = reshape (x(tri(tri_list,:),:), [nr_t, n+1, n]); |
6823 | 81 yt = y(tri(tri_list,:)); |
82 | |
83 ## Use barycentric coordinate of point to calculate yi | |
84 yi(valid) = sum (y(tri(tri_list,:)) .* bary_list, 2); | |
85 | |
86 else | |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10548
diff
changeset
|
87 error ("griddatan: unknown interpolation METHOD"); |
6823 | 88 endif |
89 | |
90 endfunction | |
91 | |
92 | |
8153
ec0a13863eb7
Only run tests that depend on HDF5 and QHull if Octave was actually
Soren Hauberg <hauberg@gmail.com>
parents:
7017
diff
changeset
|
93 %!testif HAVE_QHULL |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
94 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
6823 | 95 %! xi = [xx(:), yy(:)]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
96 %! x = 2*rand (100,2) - 1; |
6823 | 97 %! x = [x;1,1;1,-1;-1,-1;-1,1]; |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
98 %! y = sin (2 * sum (x.^2,2)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 %! zz = griddatan (x,y,xi,"linear"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
100 %! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2),"linear"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
101 %! assert (zz, zz2, 1e-10); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
102 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
103 %!testif HAVE_QHULL |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
104 %! [xx,yy] = meshgrid (linspace (-1,1,32)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 %! xi = [xx(:), yy(:)]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
106 %! x = 2*rand (100,2) - 1; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
107 %! x = [x;1,1;1,-1;-1,-1;-1,1]; |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
108 %! y = sin (2*sum (x.^2,2)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
109 %! zz = griddatan (x,y,xi,"nearest"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
110 %! zz2 = griddata (x(:,1),x(:,2),y,xi(:,1),xi(:,2),"nearest"); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
111 %! assert (zz, zz2, 1e-10); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
112 |