comparison scripts/geometry/griddatan.m @ 11587:c792872f8942

all script files: untabify and strip trailing whitespace
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:35:29 -0500
parents fd0a3ac60b0e
children 72c96de7a403
comparison
equal deleted inserted replaced
11586:12df7854fa7c 11587:c792872f8942
16 ## along with Octave; see the file COPYING. If not, see 16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>. 17 ## <http://www.gnu.org/licenses/>.
18 18
19 ## -*- texinfo -*- 19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}, @var{options}) 20 ## @deftypefn {Function File} {@var{yi} =} griddatan (@var{x}, @var{y}, @var{xi}, @var{method}, @var{options})
21 ## 21 ##
22 ## Generate a regular mesh from irregular data using interpolation. 22 ## Generate a regular mesh from irregular data using interpolation.
23 ## The function is defined by @code{@var{y} = f (@var{x})}. 23 ## The function is defined by @code{@var{y} = f (@var{x})}.
24 ## The interpolation points are all @var{xi}. 24 ## The interpolation points are all @var{xi}.
25 ## 25 ##
26 ## The interpolation method can be @code{"nearest"} or @code{"linear"}. 26 ## The interpolation method can be @code{"nearest"} or @code{"linear"}.
27 ## If method is omitted it defaults to @code{"linear"}. 27 ## If method is omitted it defaults to @code{"linear"}.
28 ## @seealso{griddata, delaunayn} 28 ## @seealso{griddata, delaunayn}
29 ## @end deftypefn 29 ## @end deftypefn
33 function yi = griddatan (x, y, xi, method, varargin) 33 function yi = griddatan (x, y, xi, method, varargin)
34 34
35 if (nargin == 3) 35 if (nargin == 3)
36 method = "linear"; 36 method = "linear";
37 endif 37 endif
38 if (nargin < 3) 38 if (nargin < 3)
39 print_usage (); 39 print_usage ();
40 endif 40 endif
41 41
42 if (ischar (method)) 42 if (ischar (method))
43 method = tolower (method); 43 method = tolower (method);
44 endif 44 endif
45 45
46 [m, n] = size (x); 46 [m, n] = size (x);
47 [mi, ni] = size (xi); 47 [mi, ni] = size (xi);
48 48
49 if (n != ni || size (y, 1) != m || size (y, 2) != 1) 49 if (n != ni || size (y, 1) != m || size (y, 2) != 1)
50 error ("griddatan: dimensional mismatch"); 50 error ("griddatan: dimensional mismatch");
51 endif 51 endif
52 52
53 ## triangulate data 53 ## triangulate data
54 ## tri = delaunayn(x, varargin{:}); 54 ## tri = delaunayn(x, varargin{:});
55 tri = delaunayn (x); 55 tri = delaunayn (x);
56 56
57 yi = NaN (mi, 1); 57 yi = NaN (mi, 1);
58 58
59 if (strcmp (method, "nearest")) 59 if (strcmp (method, "nearest"))
60 ## search index of nearest point 60 ## search index of nearest point
61 idx = dsearchn (x, tri, xi); 61 idx = dsearchn (x, tri, xi);
62 valid = !isnan (idx); 62 valid = !isnan (idx);
63 yi(valid) = y(idx(valid)); 63 yi(valid) = y(idx(valid));