📄 pop_selectevent.m
字号:
if EEG.trials > 1 geometry = { geometry{:} [2 1] }; uilist = { uilist{:} ... { 'Style', 'checkbox', 'string','Remove epochs not referenced by any selected event', ... 'fontweight', 'bold', 'value', 1 } { } }; end; results = inputgui( geometry, uilist, 'pophelp(''pop_selectevent'')', 'Select events -- pop_selectevent()'); if length(results) == 0, return; end; % decode inputs % ------------- args = {}; if ~results{2}, args = { args{:}, 'event', eval( [ '[' results{1} ']' ]) }; else args = { args{:}, 'omitevent', eval( [ '[' results{1} ']' ]) }; end; for index = 1:length(allfields) tmpres = results{2*index+1}; if isempty(findstr(tmpres, '<=')), try, tmpres = eval( [ '[' tmpres ']' ] ); catch, tmpres = parsetxt( tmpres ); end; end; if ~results{2*index+2}, args = { args{:}, allfields{index}, tmpres }; else args = { args{:}, [ 'omit' allfields{index}], tmpres }; end; end; if EEG.trials > 1 if results{end-4}, args = { args{:}, 'select', 'inverse' }; end; if ~isempty(results{end-3}), args = { args{:}, 'renametype', results{end-3} }; end; if ~isempty(results{end-2}), args = { args{:}, 'oldtypefield', results{end-2} }; end; args = { args{:}, 'deleteevents', fastif(results{end-1}, 'on', 'off') }; args = { args{:}, 'deleteepochs', fastif(results{end}, 'on', 'off') }; else if results{end-3}, args = { args{:}, 'select', 'inverse' }; end; if ~isempty(results{end-2}), args = { args{:}, 'renametype', results{end-2} }; end; if ~isempty(results{end-1}), args = { args{:}, 'oldtypefield', results{end-1} }; end; args = { args{:}, 'deleteevents', fastif(results{end}, 'on', 'off') }; end;else % no interactive inputs args = varargin; for i=1:length(varargin) if iscell(args{i}), args{i} = { args{i} }; end; % double nested end; end;% setting default for the structure% ---------------------------------fieldlist = { 'event' 'integer' [] [1:length(EEG.event)] ; 'omitevent' 'integer' [] [] ; 'deleteepochs' 'string' { 'yes' 'no' 'on' 'off' } 'on' ; 'deleteevents' 'string' { 'yes' 'no' 'on' 'off' } 'off'; 'renametype' 'string' [] ''; 'oldtypefield' 'string' [] ''; 'select' 'string' { 'normal' 'inverse' 'remove' 'keep' } 'normal' };for index = 1:length(allfields) fieldlist{end+1, 1} = allfields{index}; fieldlist{end , 2} = ''; fieldlist{end+1, 1} = [ 'omit' allfields{index} ]; fieldlist{end , 2} = '';end;g = finputcheck( args, fieldlist, 'pop_selectevent');if isstr(g), error(g); end;if isempty(g.event), g.event = [1:length(EEG.event)]; end;if strcmpi(g.select, 'remove'), g.select = 'inverse'; end;if strcmpi(g.select, 'keep' ), g.select = 'normal'; end;if strcmpi(g.deleteepochs, 'yes' ), g.deleteepochs = 'on'; end;if strcmpi(g.deleteepochs, 'no' ), g.deleteepochs = 'off'; end;if ~isempty(g.oldtypefield) & isempty(g.renametype) error('A name for the new type must be defined');end;% select the events to keep% -------------------------Ievent = g.event;Ieventrem = g.omitevent;for index = 1:length(allfields) % convert the value if the field is a string field % ------------------------------------------------ tmpvar = getfield(g, {1}, allfields{index}); if ~isempty(tmpvar) if isnumeric(tmpvar) if isstr(getfield( EEG.event, {1}, allfields{index})) for tmpind = 1:length(tmpvar) tmpvartmp{tmpind} = num2str(tmpvar(tmpind)); end; tmpvar = tmpvartmp; end; elseif isstr(tmpvar) & isempty( findstr(tmpvar, '<=')) if isnumeric(getfield( EEG.event, {1}, allfields{index})) error(['numerical values must be entered for field ''' allfields{index} '''']); end; end; end; if isstr(tmpvar) & isempty( findstr(tmpvar, '<=')) tmpvar = { tmpvar }; end; % scan each field of EEG.event % ---------------------------- if ~isempty( tmpvar ) if iscell( tmpvar ) % strings eval( [ 'tmpvarvalue = {EEG.event(:).' allfields{index} '};'] ); Ieventtmp = []; for index2 = 1:length( tmpvar ) Ieventtmp = unique( [ Ieventtmp; strmatch( tmpvar{index2}, tmpvarvalue, 'exact') ]); end; Ievent = intersect( Ievent, Ieventtmp ); elseif isstr( tmpvar ) % real range eval( [ 'tmpvarvalue = cell2mat( {EEG.event(:).' allfields{index} '});'] ); min = eval(tmpvar(1:findstr(tmpvar, '<=')-1)); max = eval(tmpvar(findstr(tmpvar, '<=')+2:end)); if strcmp(allfields{index}, 'latency') if EEG.trials > 1 tmpvarvalue = eeg_point2lat(tmpvarvalue, {EEG.event.epoch}, EEG.srate, ... [EEG.xmin EEG.xmax]*1000, 1E-3); else tmpvarvalue = eeg_point2lat(tmpvarvalue, ones(1,length(EEG.event)), EEG.srate, ... [EEG.xmin EEG.xmax], 1); end; end; if strcmp(allfields{index}, 'duration') if EEG.trials > 1, tmpvarvalue = tmpvarvalue/EEG.srate*1000; else tmpvarvalue = tmpvarvalue/EEG.srate; end; end; Ieventlow = find( tmpvarvalue >= min); Ieventhigh = find( tmpvarvalue <= max); Ievent = intersect( Ievent, intersect( Ieventlow, Ieventhigh ) ); else if strcmp(allfields{index}, 'latency') fprintf(['pop_selectevent warning: latencies are continuous values\n' ... 'so you may use the ''a<=b'' notation to select these values\n']); end; eval( [ 'tmpvarvalue = cell2mat( {EEG.event(:).' allfields{index} '});'] ); Ieventtmp = []; for index2 = 1:length( tmpvar ) Ieventtmp = unique( [ Ieventtmp find(tmpvarvalue == tmpvar(index2)) ] ); end; Ievent = intersect( Ievent, Ieventtmp ); end; end; % scan each field of EEG.event (omit) % ----------------------------------- tmpvar = eval(['g.omit' allfields{index} ]); if eval(['isstr(EEG.event(1).' allfields{index} ')' ]) & isnumeric(tmpvar) & ~isempty(tmpvar) for tmpind = 1:length(tmpvar) tmpvartmp{tmpind} = num2str(tmpvar(tmpind)); end; tmpvar = tmpvartmp; end; if isstr(tmpvar) & isempty( findstr(tmpvar, '<=')) tmpvar = { tmpvar }; end; if ~isempty( tmpvar ) if iscell( tmpvar ) eval( [ 'tmpvarvalue = {EEG.event(:).' allfields{index} '};'] ); Ieventtmp = []; for index2 = 1:length( tmpvar ) Ieventtmp = unique( [ Ieventtmp; strmatch( tmpvar{index2}, tmpvarvalue, 'exact') ]); end; Ieventrem = union( Ieventrem, Ieventtmp ); elseif isstr( tmpvar ) eval( [ 'tmpvarvalue = cell2mat( {EEG.event(:).' allfields{index} '});'] ); min = eval(tmpvar(1:findstr(tmpvar, '<=')-1)); max = eval(tmpvar(findstr(tmpvar, '<=')+2:end)); if strcmp(allfields{index}, 'latency') if EEG.trials > 1 tmpvarvalue = eeg_point2lat(tmpvarvalue, {EEG.event.epoch}, EEG.srate, ... [EEG.xmin EEG.xmax]*1000, 1E-3); else tmpvarvalue = eeg_point2lat(tmpvarvalue, ones(1,length(EEG.event)), EEG.srate, ... [EEG.xmin EEG.xmax], 1); end; end; if strcmp(allfields{index}, 'duration') if EEG.trials > 1, tmpvarvalue = tmpvarvalue/EEG.srate*1000; else tmpvarvalue = tmpvarvalue/EEG.srate; end; end; Ieventlow = find( tmpvarvalue > min); Ieventhigh = find( tmpvarvalue < max); Ieventrem = union( Ieventrem, intersect( Ieventlow, Ieventhigh ) ); else if strcmp(allfields{index}, 'latency') fprintf(['pop_selectevent warning: latencies are continuous values\n' ... 'so you may use the ''a<=b'' notation to select these values\n']); end; eval( [ 'tmpvarvalue = cell2mat( {EEG.event(:).' allfields{index} '});'] ); Ieventtmp = []; for index2 = 1:length( tmpvar ) Ieventtmp = unique( [ Ieventtmp find( tmpvarvalue ==tmpvar(index2)) ] ); end; Ieventrem = union( Ieventrem, Ieventtmp ); end; end;end;Ievent = setdiff( Ievent, Ieventrem);if strcmp(g.select, 'inverse') Ievent = setdiff( [1:length(EEG.event)], Ievent );end;% checking if trying to remove boundary events (in continuous data)if isfield(EEG.event, 'type') & isstr(EEG.event(1).type) & EEG.trials == 1 Ieventrem = setdiff([1:length(EEG.event)], Ievent ); boundaryindex = strmatch('boundary', { EEG.event(Ieventrem).type }); if ~isempty(boundaryindex) Ievent = [ Ievent Ieventrem(boundaryindex)]; end; Ievent = sort(Ievent);end;% rename events if necessary% --------------------------if ~isempty(g.renametype) fprintf('Pop_selectevent: renaming %d selected events (out of %d)\n', length(Ievent), length(EEG.event)); if ~isempty(g.oldtypefield) for index = Ievent eval([ 'EEG.event(index).' g.oldtypefield '= EEG.event(index).type;']); EEG.event(index).type = g.renametype; end; else for index = Ievent EEG.event(index).type = g.renametype; end; end;end;% Events: delete epochs% ---------------------if strcmp( lower(g.deleteepochs), 'on') & EEG.trials > 1 % ask for confirmation % -------------------- Iepoch = ones(1, EEG.trials); for index = 1:length(Ievent) Iepoch(EEG.event(Ievent(index)).epoch) = 0; end; Iepoch = find(Iepoch == 0); if length(Iepoch) == 0, error('Empty dataset: all epochs have been removed'); end; if nargin < 2 ButtonName=questdlg2(strvcat([ 'Warning: delete ' num2str(EEG.trials-length(Iepoch)) ... ' (out of ' int2str(EEG.trials) ') un-referenced epochs ?' ]), ... 'Confirmation', ... 'Cancel', 'Ok','Ok'); else ButtonName = 'ok'; end; switch lower(ButtonName), case 'cancel', return; case 'ok', if strcmpi(g.deleteevents, 'on') EEG.event = EEG.event(Ievent); end; EEG = pop_select(EEG, 'trial', Iepoch); end % switchelse % delete events if necessary % -------------------------- if strcmpi(g.deleteevents, 'on') EEG.event = EEG.event(Ievent); end;end;EEG = eeg_checkset(EEG, 'eventconsistency');% generate the output command% ---------------------------argsout = {};for index =1:2:length(args) if ~isempty(args{index+1}) argsout = { argsout{:} args{index} args{index+1}}; end;end;com = sprintf('EEG = pop_selectevent( %s, %s);', inputname(1), vararg2str(argsout));% chop the text so that it fits into the description window% ---------------------------------------------------------function chopedtext = choptext( tmptext ) chopedtext = ''; while length(tmptext) > 30 blanks = findstr( tmptext, ' '); [tmp I] = min( abs(blanks - 30) ); chopedtext = [ chopedtext ''' 10 ''' tmptext(1:blanks(I)) ]; tmptext = tmptext(blanks(I)+1:end); end; chopedtext = [ chopedtext ''' 10 ''' tmptext]; chopedtext = chopedtext(7:end);return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -