1 ## Copyright (C) 1995-2012 Kurt Hornik
2 ## Copyright (C) 2009 Jaroslav Hajek
4 ## This file is part of Octave.
6 ## Octave is free software; you can redistribute it and/or modify it
7 ## under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 3 of the License, or (at
9 ## your option) any later version.
11 ## Octave is distributed in the hope that it will be useful, but
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ## General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with Octave; see the file COPYING. If not, see
18 ## <http://www.gnu.org/licenses/>.
21 ## @deftypefn {Function File} {} range (@var{x})
22 ## @deftypefnx {Function File} {} range (@var{x}, @var{dim})
23 ## Return the range, i.e., the difference between the maximum and the minimum
24 ## of the input data. If @var{x} is a vector, the range is calculated over
25 ## the elements of @var{x}. If @var{x} is a matrix, the range is calculated
26 ## over each column of @var{x}.
28 ## If the optional argument @var{dim} is given, operate along this dimension.
30 ## The range is a quickly computed measure of the dispersion of a data set, but
31 ## is less accurate than @code{iqr} if there are outlying data points.
35 ## Author: KH <Kurt.Hornik@wu-wien.ac.at>
36 ## Description: Compute range
38 function y = range (x, dim)
40 if (nargin < 1 || nargin > 2)
45 y = max (x) - min (x);
47 y = max (x, [], dim) - min (x, [], dim);
53 %!assert(range (1:10), 9);
54 %!assert(range (single(1:10)), single(9));
55 %!assert(range (magic (3)), [5, 8, 5]);
56 %!assert(range (magic (3), 2), [7; 4; 7]);
57 %!assert(range (2), 0);
59 %% Test input validation
61 %!error range (1, 2, 3)