 clear all;
 close all;

 %readclassdatafiles
 hw1=csvread(hardwood.csv);
 cp1=csvread(carpet.csv);

 %hw1=csvread(biltmore31.csv);

 % cp1=csvread(MyPrismacolors1.csv);


 % concatenate them
 tt=[hw1;cp1];

 for jj=1:64
   qq(:,jj)=tt(:,jj)-mean(tt(:,jj));
 end
 xx=qq;
 % 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;

 % sort the eigenvectors in descending order
 ss=sum(ee);
 [r1,r2]=sort(ss,descend);

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

 % transform using reduced principal components
 yyt=wwt*xx;

 % plot the pc-transformed values
 figure;plot(yyt(1,1:1024),yyt(2,1:1024),.);
 hold on;plot(yyt(1,1025:end),yyt(2,1025:end),r.);
 grid on;xlabel(PC 1);ylabel(PC 2);