以下是MATLAB mean函数的问题,麻烦帮忙看看咋解决!

A=[1 3 4 5; 2 3 4 6;1 3 1 5]
对矩阵A求平均,mean(A):
如果是求平均的话,答案应该是: 1.3333 3.0000 3.0000 5.3333
为什么我这显示的答案是: 4 9 9 16

非常费解!
请问有人碰到这种情况没有? 
咋解决?
>> A=[1 3 4 5; 2 3 4 6;1 3 1 5];
>> B=mean(A)

B =

4 9 9 16

>> C=mean(A,1)
??? Error using ==> mean
Too many input arguments

我刚把这位仁兄的代码替换了我机子上的mean.m.结果还是如上,疯了!

牛魔王的故事
浏览 567回答 3
3回答

潇潇雨雨

在命令行输入which mean把结果发上来============你先把which mean的结果发上来,我怀疑你自己写过一个叫mean的函数

精慕HU

>> A=[1 3 4 5; 2 3 4 6;1 3 1 5];>> mean(A,1)ans =1.3333 3.0000 3.0000 5.3333>> mean(A,2)ans =3.25003.75002.5000>>mean(A,1)表示对列取平均,mean(A,2)表示对行取平均,mean(A)则默认为mean(A,1)

慕森王

在磁盘:\matlb\toolbox\matlab\datafun下可以找到mean,把以下原代码贴到里面去:function y = mean(x,dim)%MEAN Average or mean value.% For vectors, MEAN(X) is the mean value of the elements in X. For% matrices, MEAN(X) is a row vector containing the mean value of% each column. For N-D arrays, MEAN(X) is the mean value of the% elements along the first non-singleton dimension of X.%% MEAN(X,DIM) takes the mean along the dimension DIM of X.%% Example: If X = [0 1 2% 3 4 5]%% then mean(X,1) is [1.5 2.5 3.5] and mean(X,2) is [1% 4]%% Class support for input X:% float: double, single%% See also MEDIAN, STD, MIN, MAX, VAR, COV, MODE.% Copyright 1984-2005 The MathWorks, Inc.% $Revision: 5.17.4.3 $ $Date: 2005/05/31 16:30:46 $if nargin==1,% Determine which dimension SUM will usedim = min(find(size(x)~=1));if isempty(dim), dim = 1; endy = sum(x)/size(x,dim);elsey = sum(x,dim)/size(x,dim);end
打开App,查看更多内容
随时随地看视频慕课网APP