Mercurial > hg > octave-nkf
diff scripts/general/trapz.m @ 10690:35adf2a71f3f
Use common code block to find first non-singleton dimension.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Tue, 08 Jun 2010 22:09:25 -0700 |
parents | 95c3e38098bf |
children | be55736a0783 |
line wrap: on
line diff
--- a/scripts/general/trapz.m +++ b/scripts/general/trapz.m @@ -17,7 +17,7 @@ ## <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {@var{z} =} trapz (@var{y}) +## @deftypefn {Function File} {@var{z} =} trapz (@var{y}) ## @deftypefnx {Function File} {@var{z} =} trapz (@var{x}, @var{y}) ## @deftypefnx {Function File} {@var{z} =} trapz (@dots{}, @var{dim}) ## @@ -37,7 +37,6 @@ function z = trapz (x, y, dim) - if (nargin < 1) || (nargin > 3) print_usage (); endif @@ -61,19 +60,15 @@ endif if (! have_dim) - ## Find the first singleton dimension. - dim = 0; - while (dim < nd && sz(dim+1) == 1) - dim++; - endwhile - dim++; - if (dim > nd) + ## Find the first non-singleton dimension. + dim = find (sz > 1, 1); + if (isempty (dim)) dim = 1; endif else dim = floor (dim); if (dim < 1 || dim > nd) - error ("trapz: invalid dimension along which to sort"); + error ("trapz: invalid dimension DIM along which to sort"); endif endif