3200
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3922
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
3200
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3200
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3200
|
15 ## You should have received a copy of the GNU General Public License |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
3200
|
19 |
3453
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} studentize (@var{x}) |
|
22 ## If @var{x} is a vector, subtract its mean and divide by its standard |
3200
|
23 ## deviation. |
|
24 ## |
3453
|
25 ## If @var{x} is a matrix, do the above for each column. |
|
26 ## @end deftypefn |
3200
|
27 |
3456
|
28 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
29 ## Description: Subtract mean and divide by standard deviation |
3200
|
30 |
|
31 function t = studentize (x) |
3426
|
32 |
3200
|
33 if (nargin != 1) |
|
34 usage ("studentize (x)"); |
|
35 endif |
|
36 |
|
37 if is_vector (x) |
|
38 if (std (x) == 0) |
|
39 t = zeros (size (x)); |
|
40 else |
|
41 t = (x - mean (x)) / std (x); |
|
42 endif |
|
43 elseif is_matrix (x) |
|
44 l = ones (rows (x), 1); |
|
45 t = x - l * mean (x); |
3388
|
46 t = t ./ (l * max ([(std (t)); (! any (t))])); |
3200
|
47 else |
3458
|
48 error ("studentize: x must be a vector or a matrix"); |
3200
|
49 endif |
|
50 |
|
51 endfunction |