eeg_checkset.m
来自「含有多种ICA算法的eeglab工具箱」· M 代码 · 共 1,234 行 · 第 1/4 页
M
1,234 行
end; end; % size of data ----------- if size(EEG.data,3) ~= EEG.trials disp( ['eeg_checkset warning: 3rd dimension size of data (' int2str(size(EEG.data,3)) ... ') does not match the number of epochs (' int2str(EEG.trials) '), corrected' ]); res = com; EEG.trials = size(EEG.data,3); end; if size(EEG.data,2) ~= EEG.pnts disp( [ 'eeg_checkset warning: number of columns in data (' int2str(size(EEG.data,2)) ... ') does not match the number of points (' int2str(EEG.pnts) '): corrected' ]); res = com; EEG.pnts = size(EEG.data,2); end; % parameters coherence ------------------------- if round(EEG.srate*(EEG.xmax-EEG.xmin)+1) ~= EEG.pnts fprintf( 'eeg_checkset note: upper time limit (xmax) adjusted so (xmax-xmin)*srate+1 = number of frames\n'); if EEG.srate == 0 EEG.srate = 1; end; EEG.xmax = (EEG.pnts-1)/EEG.srate+EEG.xmin; res = com; end; % deal with event arrays % ---------------------- if ~isfield(EEG, 'event'), EEG.event = []; res = com; end; if ~isempty(EEG.event) if EEG.trials > 1 & ~isfield(EEG.event, 'epoch') if popask( [ 'eeg_checkset error: the event info structure does not contain an ''epoch'' field.' ... 'Should EEGLAB attempt to abort operation ?' 10 '(press Cancel to fix the problem from the commandline)']) error('eeg_checkset error(): user abort'); %res = com; %EEG.event = []; %EEG = eeg_checkset(EEG); %return; else res = com; return; %error('eeg_checkset error: no epoch field in event structure'); end; end; else EEG.event = []; end; if isempty(EEG.event) EEG.eventdescription = {}; end; if ~isfield(EEG, 'eventdescription') | ~iscell(EEG.eventdescription) EEG.eventdescription = cell(1, length(fieldnames(EEG.event))); res = com; else if ~isempty(EEG.event) if length(EEG.eventdescription) > length( fieldnames(EEG.event)) EEG.eventdescription = EEG.eventdescription(1:length( fieldnames(EEG.event))); elseif length(EEG.eventdescription) < length( fieldnames(EEG.event)) EEG.eventdescription(end+1:length( fieldnames(EEG.event))) = {''}; end; end; end; % create urevent if continuous data % --------------------------------- %if ~isempty(EEG.event) & ~isfield(EEG, 'urevent') % EEG.urevent = EEG.event; % disp('eeg_checkset note: creating the original event table (EEG.urevent)'); % for index = 1:length(EEG.event) % EEG.event(index).urevent = index; % end; %end; if isfield(EEG, 'urevent') & isfield(EEG.urevent, 'urevent') EEG.urevent = rmfield(EEG.urevent, 'urevent'); end; % deal with epoch arrays % ---------------------- if ~isfield(EEG, 'epoch'), EEG.epoch = []; res = com; end; if ~isfield(EEG, 'epochdescription'), EEG.epochdescription = {}; res = com; end; if ~isempty(EEG.epoch) if isstruct(EEG.epoch), l = length( EEG.epoch); else l = size( EEG.epoch, 2); end; if l ~= EEG.trials if popask( [ 'eeg_checkset error: the number of epoch indices in the epoch array/struct (' ... int2str(l) ') is different from the number of epochs in the data (' int2str(EEG.trials) ').' 10 ... 'Should EEGLAB attempt to abort operation ?' 10 '(press Cancel to fix the problem from the commandline)']) error('eeg_checkset error: user abort'); %res = com; %EEG.epoch = []; %EEG = eeg_checkset(EEG); %return; else res = com; return; %error('eeg_checkset error: epoch structure size invalid'); end; end; else EEG.epoch = []; end; % check ica % --------- eeg_options; % changed from eeglaboptions 3/30/02 -sm if ~isempty(EEG.icasphere) if ~isempty(EEG.icaweights) if size(EEG.icaweights,2) ~= size(EEG.icasphere,1) if popask( [ 'eeg_checkset error: number of columns in weights array (' int2str(size(EEG.icaweights,2)) ')' 10 ... 'does not match the number of rows in the sphere array (' int2str(size(EEG.icasphere,1)) ')' 10 ... 'Should EEGLAB remove ICA information ?' 10 '(press Cancel to fix the problem from the commandline)']) res = com; EEG.icasphere = []; EEG.icaweights = []; EEG = eeg_checkset(EEG); return; else error('eeg_checkset error: user abort'); res = com; return; %error('eeg_checkset error: invalid weight and sphere array sizes'); end; end; if size(EEG.icasphere,2) ~= size(EEG.data,1) if popask( [ 'eeg_checkset error: number of colums in sphere array (' int2str(size(EEG.icasphere,2)) ')' 10 ... 'does not match the number of rows in the sphere array (' int2str(size(EEG.data,1)) ')' 10 ... 'Should EEGLAB remove ICA information ?' 10 '(press Cancel to fix the problem from the commandline)']) res = com; EEG.icasphere = []; EEG.icaweights = []; EEG = eeg_checkset(EEG); return; else error('eeg_checkset error: user abort'); res = com; return; %error('eeg_checkset error: invalid weight and sphere array sizes'); end; end; if isempty(EEG.icaact) | (size(EEG.icaact,1) ~= size(EEG.icaweights,1)) | (size(EEG.icaact,2) ~= size(EEG.data,2)) if option_computeica fprintf('eeg_checkset: recomputing the ICA activation matrix ...\n'); res = com; if any(isnan(EEG.data(:))) fprintf('eeg_checkset: recomputing using NaN indices in first channel ...\n'); tmpindices = find(~isnan(EEG.data(1,:))); EEG.icaact = zeros(size(EEG.icaweights,1), size(EEG.data,2)); EEG.icaact(:) = NaN; EEG.icaact(:,tmpindices) = (EEG.icaweights*EEG.icasphere)*EEG.data(:,tmpindices); else EEG.icaact = (EEG.icaweights*EEG.icasphere)*EEG.data(:,:); end; EEG.icaact = reshape( EEG.icaact, size(EEG.icaact,1), EEG.pnts, EEG.trials); end; end; if isempty(EEG.icawinv) EEG.icawinv = pinv(EEG.icaweights*EEG.icasphere); % a priori same result as inv res = com; end; else disp( [ 'eeg_checkset warning: weights matrix cannot be empty if sphere matrix is not, correcting ...' ]); res = com; EEG.icasphere = []; end; if option_computeica if (ndims(EEG.icaact)) < 3 & (EEG.trials > 1) disp( [ 'eeg_checkset note: independent component made 3-D' ]); res = com; EEG.icaact = reshape(EEG.icaact, size(EEG.icaact,1), EEG.pnts, EEG.trials); end; else if ~isempty(EEG.icaact) fprintf('eeg_checkset: removing ICA activation matrix (as per edit options) ...\n'); end; EEG.icaact = []; end; else if ~isempty( EEG.icaweights ), EEG.icaweights = []; res = com; end; if ~isempty( EEG.icawinv ), EEG.icawinv = []; res = com; end; if ~isempty( EEG.icaact ), EEG.icaact = []; res = com; end; end; if isempty(EEG.icaact) EEG.icaact = []; end; % check chanlocs% -------------if ~isempty( EEG.chanlocs ) if ~isstruct( EEG.chanlocs) if exist( EEG.chanlocs ) ~= 2 disp( [ 'eeg_checkset warning: channel file does not exist or is not in Matlab path: filename removed from EEG struct' ]); EEG.chanlocs = []; res = com; else res = com; try, EEG.chanlocs = readlocs( EEG.chanlocs ); disp( [ 'eeg_checkset: channel file read' ]); catch, EEG.chanlocs = []; end; end; end; if isstruct( EEG.chanlocs) if length( EEG.chanlocs) ~= EEG.nbchan & length( EEG.chanlocs) ~= EEG.nbchan+1 disp( [ 'eeg_checkset warning: number of channels different in data and channel file/struct: channel file/struct removed' ]); EEG.chanlocs = []; res = com; end; end; if isstruct( EEG.chanlocs) if ~isstr(EEG.chanlocs(1).labels) for index = 1:length(EEG.chanlocs) if ~isstr(EEG.chanlocs(index).labels) EEG.chanlocs(index).labels = [ 'E' int2str(EEG.chanlocs(index).labels) ]; end; end; end; if isfield(EEG.chanlocs, 'shrink') & isempty(EEG.chanlocs(end).shrink) for index = 1:length(EEG.chanlocs) EEG.chanlocs(index).shrink = EEG.chanlocs(1).shrink; end; end; end;end;%if ~isfield(EEG, 'urchanlocs')% EEG.urchanlocs = EEG.chanlocs;% for index = 1:length(EEG.chanlocs)% EEG.chanlocs(index).urchan = index;% end;% disp('eeg_checkset note: creating backup chanlocs structure (urchanlocs)');%end;% check reference% ---------------if ~isfield(EEG, 'ref') EEG.ref = 'common';end;if isstr(EEG.ref) & strcmpi(EEG.ref, 'common') if length(EEG.chanlocs) > EEG.nbchan disp('Extra common reference electrode location detected'); EEG.ref = EEG.nbchan+1; end;end;% EEG.times (only for epoched datasets)% ---------if (EEG.trials > 1) EEG.times = linspace(EEG.xmin*1000, EEG.xmax*1000, EEG.pnts);else if isfield(EEG, 'times') EEG = rmfield(EEG, 'times'); end;end;if ~isfield(EEG, 'specdata') EEG.specdata = []; res = com; end;if ~isfield(EEG, 'specicaact') EEG.specicaact = []; res = com; end;if ~isfield(EEG, 'comments') EEG.comments = ''; res = com; end;if ~isfield(EEG, 'ref') | isempty(EEG.ref) EEG.ref = 'common'; res = com; end;% create fields if absent% -----------------------if ~isfield(EEG, 'reject') EEG.reject.rejjp = []; res = com; end;listf = { 'rejjp' 'rejkurt' 'rejmanual' 'rejthresh' 'rejconst', 'rejfreq' ... 'icarejjp' 'icarejkurt' 'icarejmanual' 'icarejthresh' 'icarejconst', 'icarejfreq'};for index = 1:length(listf) if ~isfield(EEG.reject, listf{index}), EEG.reject = setfield(EEG.reject, listf{index}, []); res = com; end; elecfield = [listf{index} 'E']; if ~isfield(EEG.reject, elecfield), EEG.reject = setfield(EEG.reject, elecfield, []); res = com; end; % check if electrode array is empty with rejection array is not if ~isempty(getfield(EEG.reject, listf{index})) & isempty(getfield(EEG.reject, elecfield)) nbchan = fastif( strcmp(listf{index}, 'ica'), size(EEG.icaweights,1), EEG.nbchan); EEG.reject = setfield(EEG.reject, elecfield, zeros(nbchan, length(getfield(EEG.reject, listf{index})))); res = com; end;end;if ~isfield(EEG.reject, 'rejglobal') EEG.reject.rejglobal = []; res = com; end;if ~isfield(EEG.reject, 'rejglobalE') EEG.reject.rejglobalE = []; res = com; end;% default colors for rejection% ----------------------------if ~isfield(EEG.reject, 'rejmanualcol') EEG.reject.rejmanualcol = [1.0000 1 0.783]; res = com; end;if ~isfield(EEG.reject, 'rejthreshcol') EEG.reject.rejthreshcol = [0.8487 1.0000 0.5008]; res = com; end;if ~isfield(EEG.reject, 'rejconstcol') EEG.reject.rejconstcol = [0.6940 1.0000 0.7008]; res = com; end;if ~isfield(EEG.reject, 'rejjpcol') EEG.reject.rejjpcol = [1.0000 0.6991 0.7537]; res = com; end;if ~isfield(EEG.reject, 'rejkurtcol') EEG.reject.rejkurtcol = [0.6880 0.7042 1.0000]; res = com; end;if ~isfield(EEG.reject, 'rejfreqcol') EEG.reject.rejfreqcol = [0.9596 0.7193 1.0000]; res = com; end;if ~isfield(EEG.reject, 'disprej') EEG.reject.disprej = { }; end; if ~isfield(EEG, 'stats') EEG.stats.jp = []; res = com; end;if ~isfield(EEG.stats, 'jp') EEG.stats.jp = []; res = com; end;if ~isfield(EEG.stats, 'jpE') EEG.stats.jpE = []; res = com; end;if ~isfield(EEG.stats, 'icajp') EEG.stats.icajp = []; res = com; end;if ~isfield(EEG.stats, 'icajpE') EEG.stats.icajpE = []; res = com; end;if ~isfield(EEG.stats, 'kurt') EEG.stats.kurt = []; res = com; end;if ~isfield(EEG.stats, 'kurtE') EEG.stats.kurtE = []; res = com; end;if ~isfield(EEG.stats, 'icakurt') EEG.stats.icakurt = []; res = com; end;if ~isfield(EEG.stats, 'icakurtE') EEG.stats.icakurtE = []; res = com; end;% component rejection% -------------------if ~isfield(EEG.stats, 'compenta') EEG.stats.compenta = []; res = com; end;if ~isfield(EEG.stats, 'compentr') EEG.stats.compentr = []; res = com; end;if ~isfield(EEG.stats, 'compkurta') EEG.stats.compkurta = []; res = com; end;if ~isfield(EEG.stats, 'compkurtr') EEG.stats.compkurtr = []; res = com; end;if ~isfield(EEG.stats, 'compkurtdist') EEG.stats.compkurtdist = []; res = com; end;if ~isfield(EEG.reject, 'threshold') EEG.reject.threshold = [0.8 0.8 0.8]; res = com; end;if ~isfield(EEG.reject, 'threshentropy') EEG.reject.threshentropy = 600; res = com; end;if ~isfield(EEG.reject, 'threshkurtact') EEG.reject.threshkurtact = 600; res = com; end;if ~isfield(EEG.reject, 'threshkurtdist') EEG.reject.threshkurtdist = 600; res = com; end;if ~isfield(EEG.reject, 'gcompreject') EEG.reject.gcompreject = []; res = com; end;if length(EEG.reject.gcompreject) ~= size(EEG.icaweights,1) EEG.reject.gcompreject = zeros(1, size(EEG.icaweights,1));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?