diff scripts/statistics/base/range.m @ 11436:e151e23f73bc

Overhaul base statistics functions and documentation of same. Add or improve input validation. Add input validation tests. Add functional tests. Improve or re-write documentation strings.
author Rik <octave@nomad.inbox5.com>
date Mon, 03 Jan 2011 21:23:08 -0800
parents be55736a0783
children fd0a3ac60b0e
line wrap: on
line diff
--- a/scripts/statistics/base/range.m
+++ b/scripts/statistics/base/range.m
@@ -21,13 +21,16 @@
 ## -*- texinfo -*-
 ## @deftypefn  {Function File} {} range (@var{x})
 ## @deftypefnx {Function File} {} range (@var{x}, @var{dim})
-## If @var{x} is a vector, return the range, i.e., the difference
-## between the maximum and the minimum, of the input data.
+## Return the range, i.e., the difference between the maximum and the minimum
+## of the input data.  If @var{x} is a vector, the range is calculated over
+## the elements of @var{x}.  If @var{x} is a matrix, the range is calculated
+## over each column of @var{x}.
 ##
-## If @var{x} is a matrix, do the above for each column of @var{x}.
+## If the optional argument @var{dim} is given, operate along this dimension.
 ##
-## If the optional argument @var{dim} is supplied, work along dimension
-## @var{dim}.
+## The range is a quickly computed measure of the dispersion of a data set, but
+## is less accurate than @code{iqr} if there are outlying data points.
+## @seealso{iqr, std}
 ## @end deftypefn
 
 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
@@ -44,3 +47,12 @@
   endif
 
 endfunction
+
+%!assert(range (1:10), 9)
+%!assert(range (magic (3)), [5, 8, 5])
+%!assert(range (magic (3), 2), [7; 4; 7])
+%!assert(range (2), 0)
+
+%% Test input validation
+%!error range ()
+%!error range (1, 2, 3)