6823
|
1 ## Copyright (C) 2007 David Bateman |
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
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 |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
6846
|
21 ## @deftypefn {Function File} {@var{idx} =} dsearchn (@var{x}, @var{tri}, @var{xi}) |
|
22 ## @deftypefnx {Function File} {@var{idx} =} dsearchn (@var{x}, @var{tri}, @var{xi}, @var{outval}) |
|
23 ## @deftypefnx {Function File} {@var{idx} =} dsearchn (@var{x}, @var{xi}) |
|
24 ## @deftypefnx {Function File} {[@var{idx}, @var{d}] =} dsearchn (@dots{}) |
6823
|
25 ## Returns the index @var{idx} or the closest point in @var{x} to the elements |
|
26 ## @var{xi}. If @var{outval} is supplied, then the values of @var{xi} that are |
|
27 ## not contained within one of the simplicies @var{tri} are set to |
|
28 ## @var{outval}. Generally, @var{tri} is returned from @code{delaunayn |
|
29 ## (@var{x})}. |
|
30 ## @seealso{dsearch, tsearch} |
|
31 ## @end deftypefn |
|
32 |
|
33 function [idx, d] = dsearchn (x, t, xi, outval) |
|
34 if (nargin < 2 || nargin > 4) |
|
35 print_usage (); |
|
36 endif |
|
37 |
|
38 if (nargin == 2) |
|
39 [idx, d] = __dsearchn__ (x, t); |
|
40 else |
|
41 [idx, d] = __dsearchn__ (x, xi); |
|
42 if (nargin == 4) |
|
43 idx2 = isnan (tsearchn (x, t, xi)); |
|
44 idx(idx2) = outval; |
|
45 d(idx2) = outval; |
|
46 endif |
|
47 endif |
|
48 endfunction |
|
49 |
|
50 %!shared x, tri |
|
51 %! x = [-1,-1;-1,1;1,-1]; |
|
52 %! tri = [1,2,3]; |
|
53 %!assert (dsearchn(x,tri,[1,1/3]), 3); |
|
54 %!assert (dsearchn(x,tri,[1,1/3],NaN), NaN); |
|
55 %!assert (dsearchn(x,tri,[1,1/3],NA), NA); |
|
56 %!assert (dsearchn(x,tri,[1/3,1]), 2); |
|
57 %!assert (dsearchn(x,tri,[1/3,1],NaN), NaN); |
|
58 %!assert (dsearchn(x,tri,[1/3,1],NA), NA); |