]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/range.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / range.m
1 function Q=range(Y,DIM)
2 % RANGE calculates the range of Y 
3 %  Missing values (encoded as NaN) are ignored. 
4 %
5 %  Q = range(Y)
6 %  Q = range(Y,DIM)
7 %     returns the range along dimension DIM of sample array Y.
8 %
9 %  Q = range(HIS)
10 %     returns the RANGE from the histogram HIS.
11 %     HIS must be a HISTOGRAM struct as defined in HISTO2 or HISTO3.
12 %
13 % see also: IQR, MAD, HISTO2, HISTO3, PERCENTILE, QUANTILE
14
15
16 %       $Id$
17 %       Copyright (C) 2009,2010,2011 by Alois Schloegl <alois.schloegl@gmail.com>
18 %       This function is part of the NaN-toolbox
19 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
20
21
22 %    it under the terms of the GNU General Public License as published by
23 %    the Free Software Foundation; either version 3 of the License, or
24 %    (at your option) any later version.
25 %
26 %    This program is distributed in the hope that it will be useful,
27 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
28 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 %    GNU General Public License for more details.
30 %
31 %    You should have received a copy of the GNU General Public License
32 %    along with this program; If not, see <http://www.gnu.org/licenses/>.
33
34 if nargin<2,
35         DIM = [];
36 end;
37 if isempty(DIM),
38         DIM = find(size(Y)>1,1);
39         if isempty(DIM), DIM = 1; end;
40 end;
41
42
43 if nargin<1,
44         help range
45
46 else
47         SW = isstruct(Y);
48         if SW, SW = isfield(Y,'datatype'); end;
49         if SW, SW = strcmp(Y.datatype,'HISTOGRAM'); end;
50         if SW,
51                 Q = repmat(NaN,1,size(Y.H,2)); 
52                 for k=1:size(Y.H,2);
53                         t = Y.X(find(Y.H(:,k)>0),min(size(Y.X,2),k));
54                         Q(1,k) = max(t)-min(t);
55                 end;
56         elseif isnumeric(Y) && nargin==1,
57                 Q = max(Y) - min(Y); 
58         elseif isnumeric(Y) && nargin==2,
59                 Q = max(Y,[],DIM) - min(Y,[],DIM); 
60         else 
61                 help range
62         end; 
63 end;
64
65
66