Home > vbmeg > external > mne > mne_pick_channels_cov.m

mne_pick_channels_cov

PURPOSE ^

SYNOPSIS ^

function [cov] = mne_pick_channels_cov(orig,include,exclude)

DESCRIPTION ^

 [cov] = mne_pick_channels_cov(orig,include,exclude)

 Pick desired channels from a covariance matrix

 orig      - The original covariance matrix
 include   - Channels to include (if empty, include all available)
 exclude   - Channels to exclude (if empty, do not exclude any)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [cov] = mne_pick_channels_cov(orig,include,exclude)
0002 %
0003 % [cov] = mne_pick_channels_cov(orig,include,exclude)
0004 %
0005 % Pick desired channels from a covariance matrix
0006 %
0007 % orig      - The original covariance matrix
0008 % include   - Channels to include (if empty, include all available)
0009 % exclude   - Channels to exclude (if empty, do not exclude any)
0010 %
0011 %
0012 
0013 %
0014 %
0015 %   Author : Matti Hamalainen, MGH Martinos Center
0016 %   License : BSD 3-clause
0017 %
0018 %   Revision 1.9  2006/11/21 12:53:49  msh
0019 %   Fixed error in picking
0020 %
0021 %   Revision 1.8  2006/06/29 22:12:28  msh
0022 %   Fixed errors in channel picking
0023 %
0024 %   Revision 1.7  2006/05/03 18:53:05  msh
0025 %   Approaching Matlab 6.5 backward compatibility
0026 %
0027 %   Revision 1.6  2006/04/23 15:29:40  msh
0028 %   Added MGH to the copyright
0029 %
0030 %   Revision 1.5  2006/04/18 20:44:46  msh
0031 %   Added reading of forward solution.
0032 %   Use length instead of size when appropriate
0033 %
0034 %   Revision 1.4  2006/04/15 12:21:00  msh
0035 %   Several small improvements
0036 %
0037 %   Revision 1.3  2006/04/14 15:49:49  msh
0038 %   Improved the channel selection code and added ch_names to measurement info.
0039 %
0040 %   Revision 1.2  2006/04/14 00:45:42  msh
0041 %   Added channel picking and fiff_invert_transform
0042 %
0043 %   Revision 1.1  2006/04/13 17:05:45  msh
0044 %   Added reading of bad channels to fiff_read_meas_info.m
0045 %   Added mne_pick_channels_cov.m
0046 %
0047 %
0048 
0049 me='MNE:mne_pick_channels_cov';
0050 
0051 if nargin == 1
0052     cov = orig;
0053     if isempty(cov.eig) || isempty(cov.eigvec)
0054         decompose_eigen; 
0055     end
0056     return;
0057 elseif nargin == 2
0058     exclude = [];
0059 elseif nargin ~= 3
0060     error(me,'Incorrect number of arguments');
0061 end
0062 
0063 if isempty(include) && isempty(exclude)
0064     cov = orig;
0065     if isempty(cov.eig) || isempty(cov.eigvec)
0066         decompose_eigen; 
0067     end
0068     return;
0069 end
0070 
0071 if isempty(orig.names) 
0072     error(me,'Cannot pick from a covariance matrix without channel names');
0073 end
0074 
0075 cov  = orig;
0076 %
0077 %   First do the channels to be included
0078 %
0079 sel = fiff_pick_channels(cov.names,include,exclude);
0080 if isempty(sel)
0081    error(me,'Nothing remains after picking');
0082 end
0083 %
0084 %   Select the desired stuff
0085 %
0086 if cov.diag
0087    cov.data = cov.data(sel);
0088 else
0089    cov.data = cov.data(:,sel);
0090    cov.data = cov.data(sel,:);
0091 end
0092 for p = 1:size(sel,2)
0093    names{p} = cov.names{sel(p)};
0094 end
0095 cov.names = names;
0096 cov.dim   = length(cov.names);
0097 %
0098 %   Eigenvalues and vectors are no longer valid
0099 %
0100 decompose_eigen;
0101 %
0102 return;
0103 
0104     function decompose_eigen
0105         if cov.diag 
0106             cov.eig    = cov.data;
0107             cov.eigvec = eye(cov.dim);
0108         else
0109             [ cov.eigvec, cov.eig ] = eig(cov.data);
0110             %
0111             %   We use the convention that rows of eigvec are the
0112             %   eigenvectors
0113             %
0114             cov.eigvec = cov.eigvec';
0115             cov.eig    = diag(cov.eig);
0116         end
0117     end
0118 
0119 end

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