# matlab运算结果为nan,为什么Matlab运行的结果是NaN呢，急盼解答

ch21=double(sample(1:265,9));

ch22=sample(266:895,9);

ch23=sample(896:1286,9);

ch24=sample(1287:1916,9);

ch25=sample(1917:2281,9);

ch26=sample(2282:2499,9);

ch31=sample(1:265,10);

ch32=sample(266:895,10);

ch33=sample(896:1286,10);

ch34=sample(1287:1916,10);

ch35=sample(1917:2281,10);

ch36=sample(2282:2499,10);

ch41=sample(1:265,11);

ch42=sample(266:895,11);

ch43=sample(896:1286,11);

ch44=sample(1287:1916,11);

ch45=sample(1917:2281,11);

ch46=sample(2282:2499,11);

class1=[ch21,ch31,ch41];

class2=[ch22,ch32,ch42];

class3=[ch23,ch33,ch43];

class4=[ch24,ch34,ch44];

class5=[ch25,ch35,ch45];

class6=[ch26,ch36,ch46];

class=[class1;class2;class3;class4;class5;class6];

% plot3(class1(:,1),class1(:,2),class1(:,3),'r.');

% grid on

% hold on

% plot3(class2(:,1),class2(:,2),class2(:,3),'g.');

% plot3(class3(:,1),class3(:,2),class3(:,3),'b.');

% plot3(class4(:,1),class4(:,2),class4(:,3),'g+');

% plot3(class5(:,1),class5(:,2),class5(:,3),'b+');

% plot3(class6(:,1),class6(:,2),class6(:,3),'r+');

% title('character 1-2-3');

% hold off

% figure,scatter3(ch21,ch31,ch41,'r.');

% hold on

% scatter3(ch22,ch32,ch42,'g.');

% scatter3(ch23,ch33,ch43,'b.');

% scatter3(ch24,ch34,ch44,'r+');

% scatter3(ch25,ch35,ch45,'g+');

% scatter3(ch26,ch36,ch46,'b+');

% axis([100,200,40,100,40,160])

n=1;

for i=1:4:400

for j=1:4:400

randsample1(n)=I(i,j,1);

randsample2(n)=I(i,j,2);

randsample3(n)=I(i,j,3);

n=n+1;

end

end

randsample=[randsample1;randsample2;randsample3]';

randsample = double(randsample);

alpha=[265/2499,630/2499,391/2499,630/2499,365/2499,218/2499];

mu1=[mean(ch21),mean(ch31),mean(ch41)]';

mu2=[mean(ch22),mean(ch32),mean(ch42)]';

mu3=[mean(ch23),mean(ch33),mean(ch43)]';

mu4=[mean(ch24),mean(ch34),mean(ch44)]';

mu5=[mean(ch25),mean(ch35),mean(ch45)]';

mu6=[mean(ch26),mean(ch36),mean(ch46)]';

mumu=[mu1,mu2,mu3,mu4,mu5,mu6];

sigma1=cov(class1);

sigma2=cov(class2);

sigma3=cov(class3);

sigma4=cov(class4);

sigma5=cov(class5);

sigma6=cov(class6);

sigma=[sigma1,sigma2,sigma3,sigma4,sigma5,sigma6];

m0=0;

tempmu=zeros(size(mumu));

tempsigma=zeros(size(sigma));

tempalpha=zeros(size(alpha));

% tempVaue = zeros(size(mumu));

% while abs(tempmu-mumu)>repmat([10 10 10],6,1)'||abs(tempsigma-sigma)>repmat([10 10 10],3,6)||abs(tempalpha-alpha) >[0.1,0.1,0.1,0.1,0.1,0.1]

% while norm(tempmu-mumu)>sqrt(75) || norm(tempsigma-sigma)>sqrt(300) || norm(tempalpha-alpha)>sqrt(0.03)

while sqrt(sum(sum((tempmu-mumu).^2)))+sqrt(sum(sum((tempsigma-sigma).^2)))+sqrt(sum((tempalpha-alpha).^2))>sqrt(375)

%     tempValue = abs(tempMu - munu);

tempmu=mumu;

tempsigma=sigma;

tempalpha=alpha;

for b=1:10000

for a= 1:6

detsigma = det(sigma(:,(a-1)*3+1:a*3));

M = exp((-.5)*(randsample(b,:)'-mumu(:,a))'*inv(sigma(:,(a-1)*3+1:a*3))*(randsample(b,:)'-mumu(:,a)));

Tao(a) = alpha(a)*detsigma^(-.5)*M;

end

for c=1:6

tao(c,b)=1.0/sum(Tao)*alpha(c)*detsigma^(-.5)*M;

end

end

for A = 1:6

for B = 1:10000

alpha(A) = mean(tao(A,:));

sum1=+tao(A,B)*randsample(B,:)';

sum2=+tao(A,B)*(randsample(B,:)'-mumu(:,A))*(randsample(B,:)'-mumu(:,A))';

%         end

switch A

case 1

m=size(ch21,1);

case 2

m=size(ch22,1);

case 3

m=size(ch23,1);

case 4

m=size(ch24,1);

case 5

m=size(ch25,1);

case 6

m=size(ch26,1);

end

for n=1:m

sum3=+(class(m0+n,:)'-mumu(:,A))*(class(m0+n,:)'-mumu(:,A))';

sum4 =+class(m0+n,:)';

m0=+m;

end

mumu(1:3,A)=1.0/(m+10000*alpha(A))*(sum1+sum4);

sigma(1:3,(A-1)*3+1:A*3)=1.0/(m+10000*alpha(A))*(sum3+sum2);

end

end

%     mumu=[mumu(1),mumu(2),mumu(3),mumu(4),mumu(5),mumu(6)];

%     sigma=[sigma(1),sigma(2),sigma(3),sigma(4),sigma(5),sigma(6)];

end

Mu = mumu

Sigma = sigma

Alpha = alpha

• 0
点赞
• 0
收藏
• 0
评论

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。