Home > vbmeg > external > mne > mne_write_cov.m

mne_write_cov

PURPOSE ^

SYNOPSIS ^

function mne_write_cov(fid,cov)

DESCRIPTION ^


   mne_write_cov(fid,cov)

   Write a covariance matrix to an open file

   fid     - an open file id
   cov     - the covariance matrix to write

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function mne_write_cov(fid,cov)
0002 %
0003 %
0004 %   mne_write_cov(fid,cov)
0005 %
0006 %   Write a covariance matrix to an open file
0007 %
0008 %   fid     - an open file id
0009 %   cov     - the covariance matrix to write
0010 %
0011 
0012 %
0013 %   Author : Matti Hamalainen, MGH Martinos Center
0014 %   License : BSD 3-clause
0015 %
0016 %   Revision 1.4  2007/12/10 01:02:55  msh
0017 %   Fixed writing of a diagonal covariance matrix
0018 %
0019 %   Revision 1.3  2006/05/05 03:50:40  msh
0020 %   Added routines to compute L2-norm inverse solutions.
0021 %   Added mne_write_inverse_sol_stc to write them in stc files
0022 %   Several bug fixes in other files
0023 %
0024 %   Revision 1.2  2006/05/03 18:53:06  msh
0025 %   Approaching Matlab 6.5 backward compatibility
0026 %
0027 %   Revision 1.1  2006/04/29 12:44:10  msh
0028 %   Added covariance matrix writing routines.
0029 %
0030 %
0031 
0032 me='MNE:mne_write_cov';
0033 
0034 global FIFF;
0035 if isempty(FIFF)
0036    FIFF = fiff_define_constants();
0037 end
0038 
0039 fiff_start_block(fid,FIFF.FIFFB_MNE_COV);
0040 %
0041 %   Dimensions etc.
0042 %
0043 fiff_write_int(fid,FIFF.FIFF_MNE_COV_KIND,cov.kind);
0044 fiff_write_int(fid,FIFF.FIFF_MNE_COV_DIM,cov.dim);
0045 if cov.nfree > 0
0046     fiff_write_int(fid,FIFF.FIFF_MNE_COV_NFREE,cov.nfree);
0047 end
0048 %
0049 %   Channel names
0050 %
0051 if ~isempty(cov.names)
0052     fiff_write_name_list(fid,FIFF.FIFF_MNE_ROW_NAMES,cov.names);
0053 end
0054 %
0055 %   Data
0056 %
0057 if cov.diag
0058    fiff_write_double(fid,FIFF.FIFF_MNE_COV_DIAG,cov.data);
0059 else
0060    if issparse(cov.data)
0061       fiff_write_float_sparse_rcs(fid,FIFF.FIFF_MNE_COV,cov.data);
0062    else
0063       q = 1;
0064       vals = zeros(cov.dim*(cov.dim+1)/2,1);
0065       for j = 1:cov.dim
0066           for k = 1:j
0067               vals(q) = cov.data(j,k);
0068               q = q + 1;
0069           end
0070       end
0071       fiff_write_double(fid,FIFF.FIFF_MNE_COV,vals);
0072    end
0073 end
0074 %
0075 %   Eigenvalues and vectors if present
0076 %
0077 if ~isempty(cov.eig) && ~isempty(cov.eigvec)
0078     fiff_write_float_matrix(fid,FIFF.FIFF_MNE_COV_EIGENVECTORS,cov.eigvec);
0079     fiff_write_double(fid,FIFF.FIFF_MNE_COV_EIGENVALUES,cov.eig);
0080 end
0081 %
0082 %   Projection operator
0083 %
0084 fiff_write_proj(fid,cov.projs);
0085 %
0086 %   Bad channels
0087 %
0088 if ~isempty(cov.bads)
0089     fiff_start_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0090     fiff_write_name_list(fid,FIFF.FIFF_MNE_CH_NAME_LIST,cov.bads);
0091     fiff_end_block(fid,FIFF.FIFFB_MNE_BAD_CHANNELS);
0092 end
0093 %
0094 %   Done!
0095 %
0096 fiff_end_block(fid,FIFF.FIFFB_MNE_COV);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005