# covmatrix.m源程序

[C,m]=covmatrix(X)(Calculate vector mean m, covariance c.)

function [C, m] = covmatrix(X)
%COVMATRIX Computes the covariance matrix of a vector population.
%   [C, M] = COVMATRIX(X) computes the covariance matrix C and the
%   mean vector M of a vector population organized as the rows of
%   matrix X. C is of size N-by-N and M is of size N-by-1, where N is
%   the dimension of the vectors (the number of columns of X).
[K, n] = size(X);
X = double(X);
if n==1%
C=0;
m=X；
else
%Compute an unbiased estimate of m
m=sum(X,1)/K;
%Subtract the mean from each row of X
X=X-m(ones(K,1), :);
%Computr an unbiased estimate of  C . Note that the produc is
%X'*X because the vectors are rows of X
C=(X'*X)/(K-1);
m=m';%Convert to a column vector
end


05-02 2330

03-14 3431
11-04 510
05-10 671
05-21
09-05 2万+
10-15 986
11-01 5498
09-28
09-04
12-18 45万+
11-17