MATLAB: SIGMA must be a square, symmetric, positive definite matrix

bayesianclassifierpositivesigmasquaresymmetric

Hello, I've a problem with the function mvnpdf. The error is: SIGMA must be a square, symmetric, positive definite matrix. But for me SIGMA is square, symmetric and positive. This is my code for bayesian classifier:
m=size(T{1},2);
M=zeros(K,m);
Sig=zeros(m,m,K);
n=zeros(1,K);
for k=1:K
X=T{k};
n(k)=size(X,1);
M(k,:)= mean(X);
Sig(:,:,k)=cov(X);
end
p=n/sum(n);
LV=[];
LC=[];
m=length(S);
for j=1:m
LV=[LV;k];
x=S(j,:);
pdf=[];
for l=1:K
pdf=[pdf mvnpdf(x,M(l,:),Sig(:,:,l))];
end
P=p.*pdf;
[v e]=max(P);
LC=[LC; e];
end
The values and dataset are in memory. Can someone please help me? Thanks.

Best Answer

A matrix of all NaN values (page 4 in your array) is most certainly NOT positive definite.