0001 function [cov] = mne_pick_channels_cov(orig,include,exclude)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
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
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
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
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
0112
0113
0114 cov.eigvec = cov.eigvec';
0115 cov.eig = diag(cov.eig);
0116 end
0117 end
0118
0119 end