Mercurial > hg > octave-lyh
annotate scripts/statistics/base/studentize.m @ 9245:16f53d29049f
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 May 2009 10:46:00 -0400 |
parents | 1bf0ce0930be |
children | 95c3e38098bf |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005, |
9245 | 2 ## 2006, 2007, 2009 Kurt Hornik |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
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 | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
3200 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
3200 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3200 | 19 |
3453 | 20 ## -*- texinfo -*- |
4885 | 21 ## @deftypefn {Function File} {} studentize (@var{x}, @var{dim}) |
3453 | 22 ## If @var{x} is a vector, subtract its mean and divide by its standard |
3200 | 23 ## deviation. |
24 ## | |
4885 | 25 ## If @var{x} is a matrix, do the above along the first non-singleton |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
26 ## dimension. If the optional argument @var{dim} is given then operate |
4885 | 27 ## along this dimension. |
3453 | 28 ## @end deftypefn |
3200 | 29 |
5428 | 30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3456 | 31 ## Description: Subtract mean and divide by standard deviation |
3200 | 32 |
4885 | 33 function t = studentize (x, dim) |
3426 | 34 |
4885 | 35 if (nargin != 1 && nargin != 2) |
6046 | 36 print_usage (); |
3200 | 37 endif |
38 | |
4885 | 39 nd = ndims (x); |
40 sz = size (x); | |
41 if (nargin != 2) | |
4886 | 42 ## Find the first non-singleton dimension. |
4885 | 43 dim = 1; |
4886 | 44 while (dim < nd + 1 && sz(dim) == 1) |
4885 | 45 dim = dim + 1; |
46 endwhile | |
47 if (dim > nd) | |
48 dim = 1; | |
3200 | 49 endif |
50 else | |
4886 | 51 if (! (isscalar (dim) && dim == round (dim)) |
52 && dim > 0 | |
53 && dim < (nd + 1)) | |
4885 | 54 error ("studentize: dim must be an integer and valid dimension"); |
55 endif | |
56 endif | |
57 | |
58 if (! ismatrix (x)) | |
3458 | 59 error ("studentize: x must be a vector or a matrix"); |
3200 | 60 endif |
61 | |
4886 | 62 c = sz(dim); |
4885 | 63 idx = ones (1, nd); |
4886 | 64 idx(dim) = c; |
4885 | 65 t = x - repmat (mean (x, dim), idx); |
66 t = t ./ repmat (max (cat (dim, std(t, [], dim), ! any (t, dim)), [], dim), idx); | |
67 | |
68 endfunction |