📄 pop_reref.m
字号:
{ 'style' 'text' 'string' 'Reference channel number(s), if present in data (default: []):' } ... { 'style' 'edit' 'tag' 'rerefstr' 'string' '' } ... { } ... { } ... { 'style' 'text' 'tag' 'oldref' 'enable' 'off' 'string' 'Label' } ... { 'style' 'text' 'tag' 'oldref' 'enable' 'off' 'string' 'Polar angle' } ... { 'style' 'text' 'tag' 'oldref' 'enable' 'off' 'string' 'Radius' } ... { 'style' 'checkbox' 'tag' 'reref2' 'enable' enable2 'string' 'Include current reference channel in data' 'callback' ... 'set(findobj(''parent'', gcbf, ''tag'', ''oldref''), ''enable'', fastif(get(gcbo, ''value''), ''on'', ''off''));' } ... { 'style' 'edit' 'tag' 'oldref' 'enable' 'off' 'string' '' } ... { 'style' 'edit' 'tag' 'oldref' 'enable' 'off' 'string' '' } ... { 'style' 'edit' 'tag' 'oldref' 'enable' 'off' 'string' '' } ... { 'style' 'text' 'string' strvcat('Note: by including a reference channel in your data (above), its potential may be computed when', ... 'you re-reference the data. If you have polar coordinates of the reference channel, enter them above;', ... 'If the dataset has no channel locations yet, you may leave the label and location fields empty;', ... [ 'If you have 3-D location coordinates only, then Cancel and create a new channel ' int2str(EEG.nbchan+1) ], ... 'in Edit > Channel locations. Then return to Tools > Re-reference.') } ... }; result = inputgui(geometry, uilist, 'pophelp(''pop_reref'')', 'Initial reference - pop_reref()', [], 'normal', vertgeom); if isempty(result), return; end; % decode inputs % ------------- options = { }; % ersase if result{1}, options = { 'refstate', 'averef' }; elseif result{2}, tmpres3 = eval([ '[' result{3} ']' ] ); if ~isempty( tmpres3 ) options = { 'refstate', - tmpres3 }; elseif result{4}, options = { 'refstate', EEG.nbchan+1 }; else options = { 'refstate', 0 }; end; end; if result{4}, % options = { options{:} 'method' 'withref' }; do not include here, otherwise redundant with next gui includeref = 1; if ~isempty(result{5}), options = { options{:} 'refloc' { result{5} eval(result{6}) eval(result{7}) } }; else if ~isempty(EEG.chanlocs) error('To include current reference channel in data, a channel location must be provided'); end; end; else includeref = 0; end; end; end; if length(EEG.chanlocs) == EEG.nbchan+1 includeref = 1; end; % compute new reference % --------------------- enable1 = fastif(strcmp(EEG.ref, 'averef'), 'on', 'off'); enable2 = fastif(strcmp(EEG.ref, 'averef'), 'off', 'on'); if isstr(EEG.ref) curref = EEG.ref; else if EEG.ref(1) < 0 curref = [ int2str(-EEG.ref) ' (absent from data)' ]; else curref = [ int2str(-EEG.ref) ' (present in data)' ]; end; end; geometry = { [1] [1.8 1] [1.8 1] [1.8] [1.8] [1] [1] }; uilist = { { 'style' 'text' 'string' ['Current data reference state is: ' curref] } ... { 'style' 'checkbox' 'tag' 'ave' 'value' fastif(strcmp(EEG.ref, 'averef'), 0, 1) 'string' 'Compute average reference' ... 'callback' ... [ 'set(findobj(''parent'', gcbf, ''tag'', ''reref''), ''value'', ~get(gcbo, ''value''));' ... 'set(findobj(''parent'', gcbf, ''tag'', ''rerefstr''), ''enable'', fastif(get(gcbo, ''value''), ''off'', ''on''));' ] } ... { } ... { 'style' 'checkbox' 'tag' 'reref' 'value' fastif(strcmp(EEG.ref, 'averef'), 1, 0) 'string' 'Re-reference data to channel number(s):' ... 'callback' [ 'set(findobj(''parent'', gcbf, ''tag'', ''ave''), ''value'', ~get(gcbo, ''value''));' ... 'set(findobj(''parent'', gcbf, ''tag'', ''rerefstr''), ''enable'', fastif(get(gcbo, ''value''), ''on'', ''off''));' ] } ... { 'style' 'edit' 'tag' 'rerefstr' 'string' '' 'enable' enable1 } ... { 'style' 'checkbox' 'tag' 'rerefstr' 'string' 'Retain reference channels in data (if more than one)' 'enable' enable1 } ... { 'style' 'text' 'string' [ 'Note: to include current reference in new reference, include channel ' int2str(EEG.nbchan+1) ' above' ] ... 'enable' fastif(includeref, 'on', 'off') } ... { } ... { 'style' 'checkbox' 'value' includeref 'enable' fastif(includeref, 'on', 'off') ... 'string' 'Add current reference channel to data' } }; result = inputgui(geometry, uilist, 'pophelp(''pop_reref'')', 'pop_reref - average reference or re-reference data'); if isempty(result), return; end; % decode inputs % ------------- if ~isempty(result{3}), ref = eval([ '[' result{3} ']' ] ); else ref = []; end; if result{1}, ref = []; elseif result{4} options = { options{:} 'keepref' 'on' }; end; if result{5}, options = { options{:} 'method' 'withref' }; end;else options = varargin;end;optionscall = options;% decode inputs% -------------withref = 0;keepref = 0;refstate = NaN;for index = 1:length(options) if isstr(options{index}) & strcmpi(options{index}, 'withref'); withref = 1; end; if isstr(options{index}) & strcmpi(options{index}, 'keepref'); keepref = 1; end; if isstr(options{index}) & strcmpi(options{index}, 'refstate'); refstate = options{index+1}; end;end;% add refstate if absent% ----------------------if isnan(refstate) if isfield(EEG, 'ref') options = { options{:} 'refstate' EEG.ref }; refstate = EEG.ref; else options = { options{:} 'refstate' 0 }; refstate = 0; end;end;% warn user% ---------if nargin < 2 if ~isstr(ref) & length(ref) > 1 & keepref == 0 res = questdlg2(strvcat('Using multiple references and suppressing reference channels', ... 'reduces the dimensionality of the data. Do you want to continue ?'), 'warning', 'Cancel', 'Yes', 'yes'); if strcmpi(res, 'Cancel'), return; end; end;end;% include channel location file% -----------------------------if ~isempty(EEG.chanlocs) optionscall = { optionscall{:} 'elocs' EEG.chanlocs }; end; % include ICA or not% ------------------if ~isempty(EEG.icaweights) optionscall = { optionscall{:} 'icaweight' EEG.icaweights*EEG.icasphere }; [EEG.data EEG.chanlocs EEG.icaweights EEG.icasphere] = reref(EEG.data, ref, optionscall{:});else [EEG.data EEG.chanlocs ] = reref(EEG.data, ref, optionscall{:});end;% add a tag in the dataset and clear some fields% ----------------------------------------------if isempty(ref) EEG.ref = 'averef';else if length(ref) == 1 if withref == 1 EEG.ref = EEG.nbchan+1; else EEG.ref = -ref; end; else if keepref EEG.ref = ref; else EEG.ref = -ref; end; end;end;EEG.icaact = [];EEG.icawinv = [];EEG.nbchan = size(EEG.data,1);EEG = eeg_checkset(EEG);if ~isempty(EEG.chanlocs) if ( length(options) > 1 & strcmpi(options{1}, 'refloc') ) | ... ( length(options) > 3 & strcmpi(options{3}, 'refloc') ) EEG = eeg_checkset(EEG, 'chanlocs_homogeneous'); if ~isfield(EEG.chanlocs, 'X') | isempty(EEG.chanlocs(end).X) tmp = convertlocs(EEG.chanlocs(end), 'topo2all'); fieldtmp = fieldnames(tmp); for index = 1:length(fieldtmp) tmpval = getfield(tmp, fieldtmp{index}); EEG.chanlocs(end) = setfield(EEG.chanlocs(end), fieldtmp{index}, tmpval); end; end; end;end;% generate the output command% ---------------------------com = sprintf('%s = pop_reref( %s, %s);', inputname(1), inputname(1), vararg2str({ref, options{:}}));return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -