[21589] | 1 | % [SVD1,SVD2,PC1,PC2,EXPVAR,Lambda] = CALSVD2(A,B,N) Compute SVDs
|
---|
| 2 | %
|
---|
| 3 | % Ref: H. Bjornson and S.A. Venegas: "A manual for EOF and SVD -
|
---|
| 4 | % Analyses of climatic Data" 1997
|
---|
| 5 | %================================================================
|
---|
| 6 | %
|
---|
| 7 | % Guillaume MAZE - LPO/LMD - March 2004
|
---|
| 8 | % gmaze@univ-brest.fr
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | function [e1,e2,pc1,pc2,expvar,Lambda,dsumCF] = calsvd2(A,B,N);
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | %================================================================
|
---|
| 15 | % Ref: H. Bjornson and S.A. Venegas: "A manual for EOF and SVD -
|
---|
| 16 | % Analyses of climatic Data" 1997 => p18
|
---|
| 17 |
|
---|
| 18 | % Assume that A is (time*map) matrix
|
---|
| 19 | [n p]=size(A);
|
---|
| 20 |
|
---|
| 21 | % Remove the mean of each column (ie the time mean in each station records)
|
---|
| 22 | S=detrend(A,'constant');
|
---|
| 23 | P=detrend(B,'constant');
|
---|
| 24 |
|
---|
| 25 | % Form the covariance matrix:
|
---|
| 26 | C=S'*P;
|
---|
| 27 |
|
---|
| 28 | % Find eigenvectors and singular values
|
---|
| 29 | [U,Lambda,V] = svds(C,N);
|
---|
| 30 |
|
---|
| 31 | % PC
|
---|
| 32 | a=S*U;
|
---|
| 33 | b=P*V;
|
---|
| 34 |
|
---|
| 35 | % Make them clear for output
|
---|
| 36 | for iN=1:N
|
---|
| 37 | e1(iN,:) = squeeze( U(:,iN) )';
|
---|
| 38 | pc1(iN,:) = squeeze( a(:,iN) )';
|
---|
| 39 | e2(iN,:) = squeeze( V(:,iN) )';
|
---|
| 40 | pc2(iN,:) = squeeze( b(:,iN) )';
|
---|
| 41 | end
|
---|
| 42 |
|
---|
| 43 | % Amount of variance explained a 0.1 pres et en %
|
---|
| 44 | L2=Lambda.^2;
|
---|
| 45 | dsum=diag(L2)/trace(L2);
|
---|
| 46 | for iN=1:N
|
---|
| 47 | expvar(iN)=fix( ( dsum(iN)*100/sum(dsum) )*10 ) /10;
|
---|
| 48 | end
|
---|
| 49 |
|
---|