Mercurial > octave
comparison scripts/statistics/mean.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 = mean (a) | |
2 | |
3 # usage: mean (a) | |
4 # | |
5 # For vector arguments, return the mean the values. | |
6 # | |
7 # For matrix arguments, return a row vector containing the mean for | |
8 # each column. | |
9 # | |
10 # See also: median, std | |
11 | |
12 if (nargin != 1) | |
13 error ("usage: mean (a)"); | |
14 endif | |
15 | |
16 [nr, nc] = size (a); | |
17 if (nr == 1 || nc == 1) | |
18 retval = sum (a) / length (a); | |
19 elseif (nr > 0 && nc > 0) | |
20 retval = sum (a) / nr; | |
21 else | |
22 error ("mean: invalid matrix argument"); | |
23 endif | |
24 | |
25 endfunction |