[E,V,A,C]=eeof(X,M,convert)%Syntax:[E,V,A,C]=eeof(X,M);[E,V,A,C]=eeof(X,M,1);%Thisfunctionperformsanextendedempiricalorthogonal%function(EEOF)analysisofmatrix'X',forembeddingdimension'M'.%EachoftheLcolumnsofXisatimeseriesoflengthN.%%Returns:E-eigenfunctionmatrix.(LMbyLM)%V-vectorcontainingvariances(unnormalizedeigenvalues).%A-matrixofprincipalcomponents.%C-lag-covariancematrix.%%Visorderedfromlargetosmall:EandAaresortedaccordingly.%%NotethatXisassumedtobecentered.Tocenterthedata,use%thecommands:%[r,c]=size(X);X=X-ones(r,1)*mean(X);beforerunningEEOF.%Ifyoualsowanttostandardizethedata,use:%X=X./(ones(r,1)*std(X));.%%Ifathirdargumentissupplied,theeigenfunctions/valueswill%bereorderedintothesameformatasMSSAoutput-i.e.Lblocks%ofsizeMratherthanMblocksofsizeL.%%Thisfunctionprovidesthesameoutput,withinnumericallydetermined%limits,asMSSAmethodsusingBroomhead-Kingtypecovarianceestimation:%itisintendedasacheckonthosefunctions.%%Notethatthisfunctionis*extremely*computationallyintensive%forlargematricesandlags.Forexample,ifXis1000by1000,%andM=5,EEOFwilltakeabout10hoursonaCrayYMP!Inputting%asubsetofthePCsofXratherthanthefulldatamatrixcan%substantiallyreducethecomputationalload.%%WrittenbyEricBreitenberger.Versiondate1/11/96%Pleasesendcommentsandsuggestionstoeric@gi.alaska.edu%[N,L]=size(X);ifM*L=N-M+1,disp('Warning:Covariancematrixmaybeill-conditioned.'),end%Createtheextendedmatrix:T=zeros(N-M+1,M*L);fori=1:MT(:,L*(i-1)+1:L*i)=X(i:N-M+i,:);end%Computetheeigenvectors/valuesofthecovariancematrix:C=(T'*T)/(N-M+1);clearX[E,V]=eig(C);V=diag(V);A=T*E;%computeprincipalcomponentsifnargin==3%PrepareMSSA-styleoutput:%sortE,V,C,andAfromMblocksofLtoLblocksofM.ind=1:L:(M-1)*L+1;fori=1:L,index=[indexind+i-1];endE=E(index,index);V=V(index);%sortthecovariancematrixandPCs:C=C(index,index);A=A(:,index);end%Sorteigenvalues/vectors/PCsindescendingorder:[V,ind]=sort(-V);V=-V';E=E(:,ind);A=A(:,ind);[F,L,B]=eof(X,n,s);%EOFcalculatestheempiricalorthogonalfunctions%andamplitudes(principalcomponents)ofthedatamatrix'X'.%Syntax:[F,L,B]=eof(X);[F,L,B]=eof(X,.9,'norm');%%Input:X-datamatrix.Forastandard(S-mode)EOFanalysis,%thecolumnsofXaretimeseries,whiletherows%arespatialmaps.Theeigenfunctionsinthiscase%willbespatialpatterns,andtheprincipal%componentsaretimeseries.%n-numberofeigenfunctionstoreturn(optional).%Ifnislessthan1,itisinterpretedas%afractionalvariance(e.g.n=.9),andenough%eigenvectorsarereturnedtoaccountforn*100%%ofthevariance.ThedefaultistoreturnallEOFs.%s-Normalizationoption.Ifs='norm',theneach%columnofXwillbenormalized(assigned%unitvariance).Ifsisnotspecified,the%dataarenotnormalized.%%Output:F-eigenfunctionmatrix(columnsareeigenvectors).%L-vectorofeigenvalues.(alleigenvaluesarereturned)%B-principalcomponentsmatrix.%%WrittenbyEricBreitenberger.Versiondate1/11/96%Pleasesendcommentsandsuggestionstoeric@gi.alaska.edu%[r,c]=size(X);ifcr,disp('Warning:Covariancematrixmaybeill-conditioned.'),endifnargin==1n=c;s='none';elseifnargin==2ifisstr(n)s=n;n=c;elses='none';endendX=X-ones(r,1)*mean(X);%centerthedataifs=='norm'X=X./(ones(r,1)*std(X));%normalizeelseifs~='none'error('Impropernormalizationoption.Pleasecheckinputs.')endS=X'*X;%computethecovariancematrix[F,L]=eig(S);clearS%sorteigenvectors,eigenvalues[L,i]=sort(diag(-L));L=-L';F=F(:,i);%figureouthowmanyeigenvectorstokeep:ifn1%ifnisintheformoffractionalvariance,converttoanindexvar=n*sum(L);i=find(cumsum(L)=var);n=i(1);endifcn,F=F(:,1:n);end%keeponlyfirstneigenvectorsB=X*F;%calculateprincipalcomponents(firstn)[F,L,B]=eofcent(X,n);%EOFcalculatestheempiricalorthogonalfunctions%andamplitudes(principalcomponents)ofthedatamatrix'X'.%Syntax:[F,L,B]=eof(X);[F,L,B]=eof(X,.9);%%Input:X-datamatrix.Forastandard(S-mode)EOFanalysis,%thecolumnsofXaretimeseries,whiletherows%arespatialmaps.Theeigenfunctionsinthiscase%willbespatialpatterns,andtheprincipal%componentsaretimeseries.%n-numberofeigenfunctionstoreturn(optional).%Ifnislessthan1,itisinterpretedas%afractionalvariance(e.g.n=.9),andenough%eigenvectorsarereturnedtoaccountforn*100%%ofthevariance.ThedefaultistoreturnallEOFs.%%Output:F-eigenfunctionmatrix(columnsareeigenvectors).%L-vectorofeigenvalues.(alleigenvaluesarereturned)%B-principalcomponentsmatrix.%%EOFCENTdoesthesamethingasEOF,butdoesnotallowthedatamatrixto%bemodifiedwithinthefunction,thusavoidingthememorypenaltyofpassing%thelargedatamatrixintothefunction.Ifyouwanttocenteror%standardizethedata,youmustdoitinthemainworkspacebeforecalling%EOFCENTThecommands[r,c]=size(X);X=X-ones(r,1)*mean(X);willcenterthe%data.Ifyouthenwanttostandardizethedata,useX=X./(ones(r,1)*std(X));.%%WrittenbyEricBreitenberger.Versiondate1/11/96%Pleasesendcommentsandsuggestionstoeric@gi.alaska.edu%[r,c]=size(X);ifcr,disp('Warning:Covariancematrixmaybeill-conditioned.'),endifnargin==1n=c;endS=X'*X;%computethecovariancematrix[F,L]=eig(S);clearS%sorteigenvectors,eigenvalues[L,i]=sort(diag(-L));L=-L';F=F(:,i);%figureouthow