Mercurial > hg > octave-lyh
diff scripts/statistics/base/studentize.m @ 10669:cab3b148d4e4
Improve validation of input arguments for base statistics functions.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 27 May 2010 20:12:51 -0700 |
parents | 95c3e38098bf |
children | fe3c3dfc07eb |
line wrap: on
line diff
--- a/scripts/statistics/base/studentize.m +++ b/scripts/statistics/base/studentize.m @@ -36,29 +36,25 @@ print_usage (); endif + if (!ismatrix(x) || ischar(x)) + error ("studentize: X must be a numeric matrix or vector"); + endif + nd = ndims (x); sz = size (x); if (nargin != 2) ## Find the first non-singleton dimension. - dim = 1; - while (dim < nd + 1 && sz(dim) == 1) - dim = dim + 1; - endwhile - if (dim > nd) + dim = find (sz > 1, 1); + if (isempty (dim)) dim = 1; endif else - if (! (isscalar (dim) && dim == round (dim)) - && dim > 0 - && dim < (nd + 1)) - error ("studentize: dim must be an integer and valid dimension"); + if (!(isscalar (dim) && dim == round (dim)) || + !(1 <= dim && dim <= nd)) + error ("studentize: DIM must be an integer and a valid dimension"); endif endif - if (! ismatrix (x)) - error ("studentize: x must be a vector or a matrix"); - endif - c = sz(dim); idx = ones (1, nd); idx(dim) = c;