Mercurial > hg > octave-lyh
comparison scripts/statistics/std.m @ 4:b4df021f796c
[project @ 1993-08-08 01:26:08 by jwe]
Initial revision
author | jwe |
---|---|
date | Sun, 08 Aug 1993 01:26:08 +0000 |
parents | |
children | 16a24e76d6e0 |
comparison
equal
deleted
inserted
replaced
3:9a4c07481e61 | 4:b4df021f796c |
---|---|
1 function retval = std (a) | |
2 | |
3 # usage: std (a) | |
4 # | |
5 # For vector arguments, std returns the standard deviation of the | |
6 # values. For matrix arguments, std returns a row vector containing | |
7 # the standard deviation for each column. | |
8 # | |
9 # See also: mean, median | |
10 | |
11 if (nargin != 1) | |
12 error ("usage: std (a)"); | |
13 endif | |
14 | |
15 nr = rows (a); | |
16 nc = columns (a); | |
17 if (nc == 1 && nr == 1) | |
18 retval = 0; | |
19 elseif (nc == 1 || nr == 1) | |
20 tmp = sum (a); | |
21 n = length (a); | |
22 retval = sqrt ((n * sumsq (a) - tmp .* tmp) / (n * (n - 1))); | |
23 elseif (nr > 1 && nc > 0) | |
24 tmp = sum (a); | |
25 retval = sqrt ((nr * sumsq (a) - tmp .* tmp) / (nr * (nr - 1))); | |
26 else | |
27 error ("mean: invalid matrix argument"); | |
28 endif | |
29 | |
30 endfunction |