function [pltx,plty]=finddecisionboundary(class1,class2,var1,var2,ninc) % get means and covariance matrices of training data for finding decision bound % (this section assumes that we used a linear discriminant as a classifier) cls1=[class1(:,var1) class1(:,var2)]; cls2=[class2(:,var1) class2(:,var2)]; m1=mean(cls1) m2=mean(cls2) cov1=cov(cls1) cov2=cov(cls2) invcov1=inv(cov1); invcov2=inv(cov2); logdetcov1 = log(det(cov1)); logdetcov2 = log(det(cov2)); % test each point in a 200 x 200 grid to see if it is on the decision % boundary pltx=[]; plty=[]; mini=min(min(cls1(:,1)),min(cls2(:,1))) maxi=max(max(cls1(:,1)),max(cls2(:,1))) minj=min(min(cls1(:,2)),min(cls2(:,2))) maxj=max(max(cls1(:,2)),max(cls2(:,2))) for i=mini:((maxi-mini)/ninc):maxi for j=minj:((maxj-minj)/ninc):maxj x = [i j]; d1 = -0.5 * (x-m1)*invcov1*(x-m1)' - 0.5*logdetcov1 ; d2 = -0.5 * (x-m2)*invcov2*(x-m2)' - 0.5*logdetcov2 ; % if the distance for a point to each of the classes is approximately the % same, remember it if (abs(d1-d2)<0.05) pltx=[pltx; i]; plty=[plty; j]; end; end; end;