1

K guys: What is the mean of {1, 2, 3} 2 right? Apparently not:

octave:50> B = [1, 2, 3]
B =

   1   2   3

octave:51> mean(B)
ans =

   0.42478
   0.55752
   0.73451

octave:52> B = [1;2;3]
B =

   1
   2
   3

octave:53> mean(B)
ans =

   0.42478
   0.55752
   0.73451

Do I just not know what a mean is?

4

1 回答 1

6

您可能使用的mean函数与 Octave 中定义的默认函数不同。我已经尝试了您的代码并得到2了答案。要确定这一点,请在八度提示符处输入以下命令

which mean

这是我的输出

`mean' is a function from the file /usr/share/octave/3.4.3/m/statistics/base/mean.m

如果我mean通过输入以下代码定义

function retval = mean (v)
   retval = v / e;
endfunction

mean(B)我什么时候得到不同的答案B = [1, 2, 3]

ans =

   0.36788   0.73576   1.10364

如果我输入命令which mean,我现在得到这个

`mean' is a command-line function
于 2012-11-29T17:39:49.990 回答