%for chi-square similarity matrix A=zeros(26,26) %for Bhattacharyya similarity matrix B=zeros(26,26) for i=1:25 f=filter(ones(1,50)/50,1,y(i,:)) %plot de-noise figures figure(3),subplot(5,5,i),plot(x(i,:),f) switch(i) case 1, s='dinosur267' case 2, s='dinosur268' case 3, s='dinosur269' case 4, s='dinosur274' case 5, s='dinosur276' case 6, s='dog87' case 7, s='dog88' case 8, s='dog89' case 9, s='dog90' case 10, s='dog91' case 11, s='face293' case 12, s='face294' case 13, s='face301' case 14, s='face313' case 15, s='face319' case 16, s='horse103' case 17, s='horse104' case 18, s='horse105' case 19, s='horse107' case 20, s='horse108' case 21, s='plane1122' case 22, s='plane1145' case 23, s='plane1170' case 24, s='plane1180' case 25, s='plane1191' otherwise end title(strcat(s,' (',int2str(i),')')) %calculate distance between f and g for j=i:25 g=filter(ones(1,50)/50,1,y(j,:)) %chi-square x^2: D(f,g)=inv((f-g)*(f-g)/(f+g)) d=(f-g).^2./(f+g) %When f[i]==0 and g[i]==0, above equation will has d[i]=NaN because %the divider is 0. %We need to deal with these NaN before we step further. for k=1:1025 if isnan(d(k)) d(k)=0 end end A(i,j)=sum(d) A(j,i)=A(i,j) %Bhattacharyya: D(f,g)=1-inv(sqrt(f*g)) d=sqrt(f.*g) B(i,j)=1-sum(d) B(j,i)=B(i,j) end end %display chi-square distance similarity matrix figure(4),subplot(1,2,1),colormap gray,pcolor(A),colorbar,title('chi-square statistics distance') %display Bhattacharyya distance similarity matrix figure(4),subplot(1,2,2),colormap gray,pcolor(B),colorbar,title('Bhattacharyya distance')