changeset 14371:079e6f3a0977

griddata3.m: Accept vectors of any orientation. Update docstring. * griddata3.m: Accept vectors of any orientation. Update docstring.
author Rik <octave@nomad.inbox5.com>
date Thu, 16 Feb 2012 14:18:45 -0800
parents fbdee844550c
children 3f6489feca1e
files scripts/geometry/griddata3.m
diffstat 1 files changed, 28 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/geometry/griddata3.m	Thu Feb 16 14:17:26 2012 -0800
+++ b/scripts/geometry/griddata3.m	Thu Feb 16 14:18:45 2012 -0800
@@ -17,7 +17,9 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v} @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options})
+## @deftypefn  {Function File} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v} @var{xi}, @var{yi}, @var{zi})
+## @deftypefnx {Function File} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v} @var{xi}, @var{yi}, @var{zi}, @var{method})
+## @deftypefnx {Function File} {@var{vi} =} griddata3 (@var{x}, @var{y}, @var{z}, @var{v} @var{xi}, @var{yi}, @var{zi}, @var{method}, @var{options})
 ##
 ## Generate a regular mesh from irregular data using interpolation.
 ## The function is defined by @code{@var{y} = f (@var{x},@var{y},@var{z})}.
@@ -25,7 +27,12 @@
 ##
 ## The interpolation method can be @code{"nearest"} or @code{"linear"}.
 ## If method is omitted it defaults to @code{"linear"}.
-## @seealso{griddata, delaunayn}
+##
+## The optional argument @var{options} is passed directly to Qhull when
+## computing the Delaunay triangulation used for interpolation.  See
+## @code{delaunayn} for information on the defaults and how to pass different
+## values.
+## @seealso{griddata, griddatan, delaunayn}
 ## @end deftypefn
 
 ## Author: David Bateman <dbateman@free.fr>
@@ -36,19 +43,29 @@
     print_usage ();
   endif
 
-  if (!all (size (x) == size (y) & size (x) == size(z) & size(x) == size (v)))
-    error ("griddata3: X, Y, Z, and V must be vectors of same length");
+  if (isvector (x) && isvector (y) && isvector (z) && isvector (v))
+    if (! isequal (length (x), length (y), length (z), length (v)))
+      error ("griddata: X, Y, Z, and V must be vectors of the same length");
+    endif
+  elseif (! size_equal (x, y, z, v))
+    error ("griddata: X, Y, Z, and V must have equal sizes");
   endif
 
-  ## meshgrid xi, yi and zi if they are vectors unless they
-  ## are vectors of the same length
-  if (isvector (xi) && isvector (yi) && isvector (zi)
-      && (numel (xi) != numel (yi) || numel (xi) != numel (zi)))
-    [xi, yi, zi] = meshgrid (xi, yi, zi);
+  ## meshgrid xi, yi and zi if they are vectors unless
+  ## they are vectors of the same length.
+  if (isvector (xi) && isvector (yi) && isvector (zi))
+    if (! isequal (length (xi), length (yi), length (zi)))
+      [xi, yi, zi] = meshgrid (xi, yi, zi);
+    else
+      ## Otherwise, convert to column vectors
+      xi = xi(:);
+      yi = yi(:);
+      zi = zi(:);
+    endif
   endif
 
-  if (any (size(xi) != size(yi)) || any (size(xi) != size(zi)))
-    error ("griddata3: XI, YI and ZI must be vectors or matrices of same size");
+  if (! size_equal (xi, yi, zi))
+    error ("griddata3: XI, YI, and ZI must be vectors or matrices of the same size");
   endif
 
   vi = griddatan ([x(:), y(:), z(:)], v(:), [xi(:), yi(:), zi(:)], varargin{:});