Changeset 25618


Ignore:
Timestamp:
10/01/20 10:19:17 (4 years ago)
Author:
Eric.Larour
Message:

CHG: diverse

File:
1 moved

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-larour-SLPS2020/src/m/contrib/larour/mme_autotime_correlation_matrix.m

    r25617 r25618  
    1 function matrix=mme_time_correlation_matrix(mme,type);
     1function matrix=mme_time_correlation_matrix(mme,varargin);
    22
    3         %Out of a multi model ensemble (nsamples x nsteps) of runs, build
    4         %a temporal correlation matrix (of size nsteps x nsteps)
     3        if nargin==2,
     4                type=varargin{1};
     5        elseif nargin==3,
     6                mme2=varargin{1};
     7                type=varargin{2};
     8        else
     9                error('mme_time_correlation_matrix usage error: 2 or 3 arguments only allowed!');
     10        end
    511
    6         nsamples=size(mme,1);
    7         nsteps=size(mme,2);
     12        if nargin==2,
    813
    9         %initialize with 1 in the diagonal:
    10         matrix=eye(nsteps,nsteps);
     14                %Out of a multi model ensemble (nsamples x nsteps) of runs, build
     15                %a temporal correlation matrix (of size nsteps x nsteps)
    1116
    12         %go through time steps, and fill up the top part.
    13         for i=1:nsteps,
    14                 for j=i+1:nsteps,
    15                         matrix(i,j)=corr(mme(:,i),mme(:,j),'Type',type);
    16                         matrix(j,i)=matrix(i,j);
     17                nsamples=size(mme,1);
     18                nsteps=size(mme,2);
     19
     20                %initialize with 1 in the diagonal:
     21                matrix=eye(nsteps,nsteps);
     22
     23                %go through time steps, and fill up the top part.
     24                for i=1:nsteps,
     25                        for j=i+1:nsteps,
     26                                matrix(i,j)=corr(mme(:,i),mme(:,j),'Type',type);
     27                                matrix(j,i)=matrix(i,j);
     28                        end
     29                end
     30        else
     31
     32                %Same kind of computations, except it's not autocorrelation:
     33                nsamples=size(mme,1); nsamples2=size(mme2,1);
     34                nsteps=size(mme,2); nsteps2=size(mme2,2);
     35
     36                if nsteps2~=nsteps,
     37                        error('number of time steps from both sample matrices should be identical!');
     38                end
     39                if nsamples2~=nsamples,
     40                        error('number of samples from both sample matrices should be identical!');
     41                end
     42
     43                %initialize with 1 in the diagonal:
     44                matrix=zeros(nsteps,nsteps);
     45
     46                %go through time steps, and fill up the top part.
     47                for i=1:nsteps,
     48                        for j=i:nsteps,
     49                                matrix(i,j)=corr(mme(:,i),mme2(:,j),'Type',type);
     50                                matrix(j,i)=matrix(i,j);
     51                        end
    1752                end
    1853        end
Note: See TracChangeset for help on using the changeset viewer.