changeset 17505:e8d3d5a5a867

Merge the official development
author LYH <lyh.kernel@gmail.com>
date Thu, 26 Sep 2013 04:38:54 +0800
parents 7c14949789ab (current diff) 326af26556ea (diff)
children 9b2443f97a3e
files
diffstat 5 files changed, 99 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/hist.m
+++ b/scripts/plot/hist.m
@@ -40,7 +40,7 @@
 ## If a third argument is provided, the histogram is normalized such that
 ## the sum of the bars is equal to @var{norm}.
 ##
-## Extreme values are lumped in the first and last bins.
+## Extreme values are lumped into the first and last bins.
 ##
 ## The histogram's appearance may be modified by specifying property/value
 ## pairs.  For example the face and edge color may be modified.
@@ -64,8 +64,9 @@
 ## If the first argument @var{hax} is an axes handle, then plot into this axis,
 ## rather than the current axes returned by @code{gca}.
 ##
-## With two output arguments, produce the values @var{nn} and @var{xx} such
-## that @code{bar (@var{xx}, @var{nn})} will plot the histogram.
+## With two output arguments, produce the values @var{nn} (numbers of elements)
+## and @var{xx} (bin centers) such that @code{bar (@var{xx}, @var{nn})} will
+## plot the histogram.
 ##
 ## @seealso{histc, bar, pie, rose}
 ## @end deftypefn
@@ -85,17 +86,17 @@
 
   arg_is_vector = isvector (y);
 
-  if (rows (y) == 1)
+  if (arg_is_vector)
     y = y(:);
   endif
 
-  if (isreal (y))
-    max_val = max (y(:));
-    min_val = min (y(:));
-  else
-    error ("hist: first argument must be real valued");
+  if (! isreal (y))
+    error ("hist: Y must be real valued");
   endif
 
+  max_val = max (y(:));
+  min_val = min (y(:));
+
   iarg = 1;
   if (nargin == 1 || ischar (varargin{iarg}))
     n = 10;
@@ -107,7 +108,7 @@
     if (isscalar (x))
       n = x;
       if (n <= 0)
-        error ("hist: number of bins must be positive");
+        error ("hist: number of bins NBINS must be positive");
       endif
       x = [0.5:n]'/n;
       x = x * (max_val - min_val) + ones (size (x)) * min_val;
@@ -115,10 +116,10 @@
       if (isvector (x))
         x = x(:);
       endif
-      tmp = sort (x);
-      if (any (tmp != x))
+      xsort = sort (x);
+      if (any (xsort != x))
         warning ("hist: bin values not sorted on input");
-        x = tmp;
+        x = xsort;
       endif
     else
       error ("hist: second argument must be a scalar or a vector");
@@ -154,14 +155,15 @@
   freq = diff (chist);
 
   if (nargin > 2 && ! ischar (varargin{iarg}))
-    ## Normalise the histogram.
+    ## Normalize the histogram.
     norm = varargin{iarg++};
-    freq = freq / sum(! isnan (y)) * norm;
+    freq *= norm / sum (! isnan (y));
   endif
 
   if (nargout > 0)
-    if (arg_is_vector)
-      nn = freq';
+    if (arg_is_vector)  
+      ## Matlab compatibility requires a row vector return
+      nn = freq';  
       xx = x';
     else
       nn = freq;
--- a/scripts/plot/isprop.m
+++ b/scripts/plot/isprop.m
@@ -17,8 +17,11 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {@var{res} =} isprop (@var{h}, @var{prop})
+## @deftypefn {Function File} {@var{res} =} isprop (@var{h}, "@var{prop}")
 ## Return true if @var{prop} is a property of the object with handle @var{h}.
+##
+## @var{h} may also be an array of handles in which case @var{res} will be a
+## logical array indicating whether each handle has the property @var{prop}.
 ## @seealso{get, set}
 ## @end deftypefn
 
@@ -26,23 +29,21 @@
 
 function res = isprop (h, prop)
 
-  if (nargin < 1 || nargin > 2)
+  if (nargin != 2)
     print_usage ();
   endif
 
   if (! all (ishandle (h)))
-    error ("isprop: first input argument must be a handle");
+    error ("isprop: H must be a graphics handle or vector of handles");
   elseif (! ischar (prop))
-    error ("isprop: second input argument must be string");
+    error ("isprop: PROP name must be a string");
   endif
 
   res = false (size (h));
-  for n = 1:numel (res)
-    res(n) = true;
+  for i = 1:numel (res)
     try
-      v = get (h(n), prop);
-    catch
-      res(n) = false;
+      v = get (h(i), prop);
+      res(i) = true;
     end_try_catch
   endfor
 endfunction
@@ -52,3 +53,9 @@
 %!assert (isprop (0, "screenpixelsperinch"), true)
 %!assert (isprop (zeros (2, 3), "visible"), true (2, 3))
 
+%!error isprop ()
+%!error isprop (1)
+%!error isprop (1,2,3)
+%!error <H must be a graphics handle> isprop ({1}, "visible")
+%!error <PROP name must be a string> isprop (0, {"visible"})
+
--- a/scripts/plot/meshgrid.m
+++ b/scripts/plot/meshgrid.m
@@ -21,14 +21,34 @@
 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}, @var{zz}] =} meshgrid (@var{x}, @var{y}, @var{z})
 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}] =} meshgrid (@var{x})
 ## @deftypefnx {Function File} {[@var{xx}, @var{yy}, @var{zz}] =} meshgrid (@var{x})
-## Given vectors of @var{x} and @var{y} and @var{z} coordinates, and
-## returning 3 arguments, return three-dimensional arrays corresponding
-## to the @var{x}, @var{y}, and @var{z} coordinates of a mesh.  When
-## returning only 2 arguments, return matrices corresponding to the
-## @var{x} and @var{y} coordinates of a mesh.  The rows of @var{xx} are
-## copies of @var{x}, and the columns of @var{yy} are copies of @var{y}.
-## If @var{y} is omitted, then it is assumed to be the same as @var{x},
-## and @var{z} is assumed the same as @var{y}.
+## Given vectors of @var{x} and @var{y} coordinates, return matrices @var{xx}
+## and @var{yy} corresponding to a full 2-D grid.
+##
+## The rows of @var{xx} are copies of @var{x}, and the columns of @var{yy} are
+## copies of @var{y}.  If @var{y} is omitted, then it is assumed to be the same
+## as @var{x}.
+##
+## If the optional @var{z} input is given, or @var{zz} is requested, then the
+## output will be a full 3-D grid.
+##
+## @code{meshgrid} is most frequently used to produce input for a 2-D or 3-D
+## function that will be plotted.  The following example creates a surface
+## plot of the ``sombrero'' function.
+##
+## @example
+## f = @@(x,y) sin (sqrt (x.^2 + y.^2)) ./ sqrt (x.^2 + y.^2);
+## range = linspace (-8, 8, 41);
+## [@var{X}, @var{Y}] = meshgrid (range, range);  
+## Z = f (X, Y);
+## surf (X, Y, Z);
+## @end example
+##
+## Programming Note: @code{meshgrid} is restricted to 2-D or 3-D grid
+## generation.  The @code{ndgrid} function will generate 1-D through N-D
+## grids.  However, the functions are not completely equivalent.  If @var{x}
+## is a vector of length M and @var{y} is a vector of length N, then @code
+## meshgrid will produce an output grid which is NxM.  @code{ndgrid} will
+## produce an output which is MxN for the same input.
 ## @seealso{ndgrid, mesh, contour, surf}
 ## @end deftypefn
 
@@ -44,30 +64,27 @@
     y = x;
   endif
 
-  ## Use repmat to ensure that the result values have the same type as
-  ## the arguments.
+  ## Use repmat to ensure that result values have the same type as the inputs
 
   if (nargout < 3)
-    if (isvector (x) && isvector (y))
-      xx = repmat (x(:).', length (y), 1);
-      yy = repmat (y(:), 1, length (x));
-    else
-      error ("meshgrid: arguments must be vectors");
+    if (! (isvector (x) && isvector (y)))
+      error ("meshgrid: X and Y must be vectors");
     endif
+    xx = repmat (x(:).', length (y), 1);
+    yy = repmat (y(:), 1, length (x));
   else
     if (nargin < 3)
       z = y;
     endif
-    if (isvector (x) && isvector (y) && isvector (z))
-       lenx = length (x);
-       leny = length (y);
-       lenz = length (z);
-       xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]);
-       yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]);
-       zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
-    else
-      error ("meshgrid: arguments must be vectors");
+    if (! (isvector (x) && isvector (y) && isvector (z)))
+      error ("meshgrid: X, Y, and Z must be vectors");
     endif
+    lenx = length (x);
+    leny = length (y);
+    lenz = length (z);
+    xx = repmat (repmat (x(:).', leny, 1), [1, 1, lenz]);
+    yy = repmat (repmat (y(:), 1, lenx), [1, 1, lenz]);
+    zz = reshape (repmat (z(:).', lenx*leny, 1)(:), leny, lenx, lenz);
   endif
 
 endfunction
@@ -104,3 +121,10 @@
 %! assert (XX1, XX2);
 %! assert (YY1, YY2);
 
+%% Test input validation
+%!error meshgrid ()
+%!error meshgrid (1,2,3,4)
+%!error <X and Y must be vectors> meshgrid (ones (2,2), 1:3)
+%!error <X and Y must be vectors> meshgrid (1:3, ones (2,2))
+%!error <X, Y, and Z must be vectors> [X,Y,Z] = meshgrid (1:3, 1:3, ones (2,2))
+
--- a/scripts/plot/surfl.m
+++ b/scripts/plot/surfl.m
@@ -17,10 +17,11 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn  {Function File} {} surfl (@var{x}, @var{y}, @var{z})
-## @deftypefnx {Function File} {} surfl (@var{z})
-## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{L})
-## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{L}, @var{P})
+## @deftypefn  {Function File} {} surfl (@var{z})
+## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z})
+## @deftypefnx {Function File} {} surfl (@dots{}, @var{lsrc})
+## @deftypefnx {Function File} {} surfl (@var{x}, @var{y}, @var{z}, @var{lsrc}, @var{P})
+## @deftypefnx {Function File} {} surfl (@dots{}, "cdata")
 ## @deftypefnx {Function File} {} surfl (@dots{}, "light")
 ## @deftypefnx {Function File} {} surfl (@var{hax}, @dots{})
 ## @deftypefnx {Function File} {@var{h} =} surfl (@dots{})
@@ -38,10 +39,10 @@
 ##
 ## The default lighting mode @qcode{"cdata"}, changes the cdata property of the
 ## surface object to give the impression of a lighted surface.
-## @strong{Warning:} The alternative mode @qcode{"light"} mode which creates a light
-## object to illuminate the surface is not implemented (yet).
+## @strong{Warning:} The alternative mode @qcode{"light"} mode which creates a
+## light object to illuminate the surface is not implemented (yet).
 ##
-## The light source location can be specified using @var{L}.  It can be given
+## The light source location can be specified using @var{lsrc}.  It can be given
 ## as a 2-element vector [azimuth, elevation] in degrees, or as a 3-element
 ## vector [lx, ly, lz].  The default value is rotated 45 degrees
 ## counterclockwise to the current view.
@@ -93,7 +94,7 @@
   if (ischar (varargin{end}))
     switch (tolower (varargin{end}))
       case "light"
-        warning ("light method not supported (yet), using cdata method instead");
+        warning ("surfl: light method not supported (yet), using cdata method instead");
         ## This can be implemented when light objects are supported.
         use_cdata = false;
       case "cdata"
@@ -155,9 +156,9 @@
 
     if (! have_lv)
       ## Calculate light vector (lv) from view vector.
-      Phi = 45.0 / 180.0 * pi;
-      R = [cos(Phi), -sin(Phi), 0;
-           sin(Phi),  cos(Phi), 0;
+      phi = pi / 4;  # 45 degrees
+      R = [cos(phi), -sin(phi), 0;
+           sin(phi),  cos(phi), 0;
            0,         0,        1];
       lv = (R * vv.').';
     endif
@@ -169,15 +170,16 @@
     vn(:,:,3) *= dar(3);
 
     ## Normalize vn.
-    vn = vn ./ repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]);
+    vn ./= repmat (sqrt (sumsq (vn, 3)), [1, 1, 3]);
     [nr, nc] = size (get (htmp, "zdata"));
 
     ## Ambient, diffuse, and specular term.
     cdata = (  r(1) * ones (nr, nc)
              + r(2) * diffuse  (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv)
              + r(3) * specular (vn(:,:,1), vn(:,:,2), vn(:,:,3), lv, vv, r(4)));
+    cdata ./= sum (r(1:3));
 
-    set (htmp, "cdata", cdata ./ sum (r(1:3)));
+    set (htmp, "cdata", cdata);
 
   unwind_protect_cleanup
     if (! isempty (oldfig))
--- a/scripts/sparse/svds.m
+++ b/scripts/sparse/svds.m
@@ -297,7 +297,7 @@
 %!
 %!testif HAVE_ARPACK
 %! s = svds (speye (10));
-%! assert (s, ones (6, 1), 4*eps);
+%! assert (s, ones (6, 1), 8*eps);
 
 %!test
 %! ## Restore random number generator seeds at end of tests