MATLAB中用var()计算样本方差,用标准差函数std()计算样本标准差,用矩函数moment()计算样本的各阶中心矩。
>> x=[-1 -1 1 2];
>> w=[1 2 3 4];
>> v1=var(x)
v1 =
2.2500
>> v2=var(x,0)
v2 =
2.2500
>> v3=var(x,1)
v3 =
1.6875
>> v4=var(x,w)
v4 =
1.5600
>> v5=var(x,1,w)
出错 var (line 71)
n = size(x,dim);
>> s1=std(x)
s1 =
1.5000
>> s1=std(x,1)
s1 =
1.2990
>> s1=std(x,w)
s1 =
1.2490