function Y=andrews(X,nox) % % Andrews Diagrams: Plots high-dimensional data using the method proposed % by Andrews (1972). % Y = ANDREWS(X,N) plots each row of the matrix X as a trigonometric function % defined in the interval (-pi,pi). % N is the number of points taken into account in the interval(-pi,pi). % The default value for N is 100. % Y is the matrix containing the values f(t) of the trigonometric functions. % Reference: % D.F. Andrews (1972), "Plots of High-Dimensional data", Biometrics, pp. 125-136 % Author: % Marco Sandri - Verona - Italy - Email: sandri.marco@gmail.com % if nargin<2 nox=100; end [nrows,p]=size(X); if nrows>nox-1 disp('Warning! Number of points in (-pi,pi) too low.'); disp('N has been setted equal to the number of rows of X plus one.'); nox=nrows+1; end t=[-pi:2*pi/(nox-1):pi]; Y=zeros(nrows,nox); if mod(p,2) for j=1:nrows Y(j,:)=X(j,1)/sqrt(2).*ones(1,nox); for i=2:2:p-1 Y(j,:)=Y(j,:)+X(j,i).*sin(t*i/2)+X(j,i+1).*cos(t*i/2); end end else for j=1:nrows Y(j,:)=X(j,1)/sqrt(2).*ones(1,nox); for i=2:2:p-2 Y(j,:)=Y(j,:)+X(j,i).*sin(t*i/2)+X(j,i+1).*cos(t*i/2); end Y(j,:)=Y(j,:)+X(j,p).*sin(t*i/2); end end Ymin=min(min(Y)); Ymax=max(max(Y)); Yrange=Ymax-Ymin; Ycrt=Yrange/10; plot(t,Y); axis([-pi pi Ymin-Ycrt Ymax+Ycrt]); title('Andrews Diagrams'); xlabel('t'); ylabel('f(t)'); hold on; for i=1:nrows pos=round(nox/(nrows+1)*i); text(t(pos),Y(i,pos),num2str(i)); end; hold off;