 clear all;
 close all;

 %readtheclassdatafiles
 [num1,txt1,raw1]=xlsread(hardwood.csv);
 [num2,txt2,raw2]=xlsread(carpet.csv);

 %[num1,txt1,raw1]=xlsread(biltmore31.csv);
 %[num2,txt2,raw2]=xlsread(MyPrismacolors1.csv);


 % shuffle the observations of a class randomly
 rand(seed,129);
 nd1=randperm(1024);


 % select the observation corresponding to

 % the first 4 indexes
 t1=num1(nd1(1:4),:);


 % shuffle the observations of a class randomly
 rand(seed,131);
 nd2=randperm(1024);


 % select the observation corresponding to

 % the first 4 indexes
 t2=num2(nd2(1:4),:);
 % collect the values of the 47th feature
 x1=[t1(:,47);t2(:,47)];


 % collect the values of the 48th feature
 x2=[t1(:,48);t2(:,48)];


 % collect the values of the 49th feature
 x3=[t1(:,49);t2(:,49)];


 % center them w.r.t their means
 xx1=x1-mean(x1);
 xx2=x2-mean(x2);
 xx3=x3-mean(x3);


 % concatenate them
 xx=[xx1;xx2;xx3];


 % plot the observations
 figure;plot3(xx1,xx2,xx3,.,MarkerSize,14);
 grid on;


 % calculate covariance matrix
 C=(xx*xx)/(length(xx)-1);


 % calculate eigenvector (principal component)

 % and eigenvalue
 [ww,ee]=eig(C);


 % transform using principal components
 yy=ww*xx;

 ss=sum(ee);
 [r1,r2]=sort(ss,descend);

 kk=2;
 wwt=ww(:,r2(1:kk));

 yyt=wwt*xx;

 figure;plot3(xx1,xx2,xx3,.,MarkerSize,14);
 hold on;plot3(yy(1,:),yy(2,:),yy(3,:),r.,MarkerSize,14);
 grid on;

 figure;plot(yyt(1,:),yyt(2,:),.,MarkerSize,14);
 grid on;