Home > atmlab > covmat > covmat_append.m

covmat_append

PURPOSE ^

COVMAT_APPEND Appends a set of covariance matrices.

SYNOPSIS ^

function S = covmat_append( varargin )

DESCRIPTION ^

 COVMAT_APPEND   Appends a set of covariance matrices.

    The covariance matrices are assembled assuming no correlation between
    the quantities corresponding to each covariance matrix. That is, 
    the output has the structure:
       S = [S1  0  0 ...
             0 S2  0 ...
             0  0 S3 ...
             ........... ]

    All input matrices must be sparse.

 FORMAT   S = covmat_append( S1, S2, S3, ... )
        
 OUT   S   Complete covariance matrix.
 IN    Si  Input covariance matrix.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

covmat_append.m

SOURCE CODE ^

0001 % COVMAT_APPEND   Appends a set of covariance matrices.
0002 %
0003 %    The covariance matrices are assembled assuming no correlation between
0004 %    the quantities corresponding to each covariance matrix. That is,
0005 %    the output has the structure:
0006 %       S = [S1  0  0 ...
0007 %             0 S2  0 ...
0008 %             0  0 S3 ...
0009 %             ........... ]
0010 %
0011 %    All input matrices must be sparse.
0012 %
0013 % FORMAT   S = covmat_append( S1, S2, S3, ... )
0014 %
0015 % OUT   S   Complete covariance matrix.
0016 % IN    Si  Input covariance matrix.
0017 
0018 % 2005-05-20   Created by Patrick Eriksson.
0019 
0020 
0021 function S = covmat_append( varargin )
0022 
0023 i = [];
0024 j = [];
0025 s = [];
0026 n = 0;
0027 
0028 for a = 1 : length(varargin )
0029 
0030   if ~( isempty( varargin{a} )  |  ...
0031      ( sparse( varargin{a} )  &  size(varargin{a},1) == size(varargin{a},2) ) )
0032     error( 'All covariance matrices must be square and sparse.' );
0033   end
0034 
0035   [ii,jj,ss] = find( varargin{a} );
0036 
0037   i = [ i; vec2col(n+ii) ];
0038   j = [ j; vec2col(n+jj) ];
0039   s = [ s; vec2col(ss) ];
0040 
0041   n = n + size( varargin{a}, 1 );
0042 
0043 end
0044 
0045 S = sparse(i,j,s,n,n);

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005