matlab中协方差矩阵的结果

时间:2016-03-30 22:36:14

标签: algorithm matlab matlab-guide

ex1 ex1_2 我正在按照提供的示例进行操作。我想知道该示例是如何得出 S1 S1 的结果的。我在maltlab中写了相同的代码 S1 = 4 * cov(c1)**但是如果我做了以下代码,结果就不一样了,对于** S2 ,你能告诉我吗?我怎样才能在示例中获得相同的结果?这是2乘2矩阵。 S1 = [10 8; 8 7.2],S2 = [17.3 16; 16 16]。

x1=[1 2;2 3;3 3;4 5;5 5]'  % the first class 5 observations
x2=[1 0;2 1;3 1;3 2;5 3]'
m1 = mean(x1')'; 
m2 = mean(x2')'; 
m = m1 + m2; 
 Sw1 = zeros(size(x1, 1), size(x1,1)); % here Sw1 is different from example
 Sw2 = zeros(size(x1, 1), size(x1,1)); % the same for Sw2
for i = 1:size(x1,1)
    Sw1 =  Sw1 + (x1(:,i)-m1)*(x1(:,i)-m1)';
end
for i = 1:size(x2,1)
    Sw2 =  Sw2 + (x2(:,i)-m2)*(x2(:,i)-m2)';
end


Sw = Sw1 + Sw2; 
w = Sw^(-1)*(m2-m1);

0 个答案:

没有答案