⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eeg_context.m

📁 含有多种ICA算法的eeglab工具箱
💻 M
📖 第 1 页 / 共 2 页
字号:
                  end                end              end              if is0epoch                 break;               end            end % for            if ~is0epoch                  noepochs = noepochs+1;            end       end       targs(targetcount) = evidx;                  % save event index       ur_trgs(targetcount) = uridx;                % save urevent index       if ~exist('NO_FIELD','var')         if cellfld ==0            tfields(targetcount) = EEG.urevent(uridx).(field);         elseif cellfld == 1            tfields{targetcount} = EEG.urevent(uridx).(field);         end         break                                        % stop target type checking       end    else % next target type       tidx = tidx+1;                                   % else try next target type    end % if is target end % while ~istarget if istarget  % if current event is a target type  if ~isempty(negpos)   %   %%%%%%%%%%%%%%%%%% find previous neighbor urevents %%%%%%%%%%%%   %   uidx = uridx-1;                                   % begin with the previous urevent   npidx  = 1;                                       % index into negpos   curpos = 1;                                       % current (negative) position   seekpos = negpos(npidx);                          % begin with first negpos position   while uidx > 0 && npidx <= nnegpos                 % search through previous urevents     if strcmpi(num2str(EEG.urevent(uidx).type),'boundary')  % flag boundary urevents        if ~isfield(EEG.urevent,'duration') ...          || isnan(EEG.urevent(uidx).duration) % pre-v4.4 or real break urevent (NaN duration)             if ~isfield(EEG.urevent,'duration') ... % pre version-4.4 dataset                    && breakwarning == 0               fprintf('Pre-v4.4 boundary urevent found - duration field not defined.');               breakwarning = 1;             end             break           % don't search for neighbors across a boundary urevent        end     end     isneighbor = 0;                                 % initialize neighbor flag     nidx = 1;                                       % initialize neighbor type index     %     %%%%%%%%%% cycle through neighbor types %%%%%%%%%%%%%     %     while ~isneighbor && nidx<=length(neighbors)     % for each neighbor event type       if strcmpi(num2str(EEG.urevent(uidx).type),neighbors(nidx)) || strcmp(neighbors,'_ALL')         isneighbor=1;                               % flag 'neighbors' event         curpos = curpos+1;         %         %%%%%%%%%%%%%%% if an event in one of the specified positions %%%%%         %         if curpos-1 == seekpos           delays(targetcount,negidx(npidx)) = 1000/EEG.srate * ...                                (EEG.urevent(uidx).latency - EEG.urevent(uridx).latency);                                % return negative latencies for negpos events           ur_nbrs(targetcount,negidx(npidx))=uidx;  % mark urevent as neighbor           ur_nbrtypes(targetcount,negidx(npidx)) = nidx;           if ~exist('NO_FIELD','var')             if cellfld ==0              nfields(targetcount,negidx(npidx)) = EEG.urevent(uidx).(field);             elseif cellfld == 1              nfields{targetcount,negidx(npidx)} = EEG.urevent(uidx).(field);             end           end           npidx = npidx+1;  % look for next negpos position           if npidx<=nnegpos              seekpos = negpos(npidx);               % new seek position           end         end % if seekpos         break                                       % stop neighbors type checking       else         nidx = nidx+1;                              % try next 'neighbors' event type       end     end  % nidx - neighbor-type testing loop     %     %%%%%%%%%%%%%%% find preceding neighbor event %%%%%%%%%%%%%%     %     uidx = uidx-1;                     % keep checking for a 'neighbors' type event   end % while uidx - urevent type checking  end % if negpos   if ~isempty(pospos)   %   %%%%%%%%%%%%%%% find succeeding position urevents %%%%%%%%%%%%   %   uidx = uridx+1;                                   % begin with the succeeding urevent   ppidx  = 1;                                       % index into pospos   curpos = 1;                                       % current (positive) position   seekpos = pospos(ppidx);                          % begin with first pospos position   while uidx <= nurevents  && ppidx <= npospos       % search through succeeding urevents     isneighbor = 0;                                 % initialize neighbor flag     if strcmpi(num2str(EEG.urevent(uidx).type),'boundary')  % flag boundary events        if ~isfield(EEG.urevent,'duration')  ...     % pre version-4.4 dataset          || EEG.urevent(uidx).duration == 0          % real break urevent (no duration)             if ~isfield(EEG.urevent,'duration') ... % pre version-4.4 dataset                    && breakwarning == 0               fprintf('Pre-4.4 boundary urevent found - duration not defined.');               breakwarning = 1;             end             break      % don't search for neighbors across a boundary urevent        end     end     pidx = 1;                                       % initialize neighbor type index     %     %%%%%%%%%% cycle through neighbor types %%%%%%%%%%%%%     %     while ~isneighbor && pidx<=length(neighbors)     % for each neighbor event type       if strcmpi(num2str(EEG.urevent(uidx).type),neighbors(pidx)) || strcmp(neighbors,'_ALL')         isneighbor=1;                               % flag 'neighbors' event         curpos = curpos+1;         %         %%%% if an event in one of the specified positions %%%%%         %         if curpos-1 == seekpos           ur_nbrs(targetcount,posidx(ppidx))=uidx;  % mark urevent as neighbor           % ur_nbrtypes{targetcount,posidx(ppidx)} = EEG.urevent(uidx).type; % note its type           ur_nbrtypes(targetcount,posidx(ppidx)) = pidx; % note its type           delays(targetcount,posidx(ppidx)) = 1000/EEG.srate * ...                                (EEG.urevent(uidx).latency - EEG.urevent(uridx).latency);                                % return positive latencies for pospos events           if ~exist('NO_FIELD','var')             if cellfld ==0                nfields(targetcount,posidx(ppidx)) = EEG.urevent(uidx).(field);             elseif cellfld == 1                nfields{targetcount,posidx(ppidx)} = EEG.urevent(uidx).(field);             end           end           ppidx = ppidx+1;           if ppidx<=npospos              seekpos = pospos(ppidx);               % new seek position           end           break                                    % stop neighbors type checking         end % if seekpos         break       else         %         %%%%%%%%%%%% find succeeding neighbor event %%%%%%%%%%%%         %         pidx = pidx+1;                              % try next 'neighbors' event-type       end     end  % pidx - neighbor-type testing loop     uidx = uidx+1;                     % keep checking for 'neighbors' type urevents   end % uidx - urevent type checking  end % if pospos   %  %%%%%%%%%%%%%%% debug mode info printout %%%%%%%%%%%%%%%%%%%%%%  %  if debug_print    fprintf('%d. ',targetcount)    if targetcount<1000, fprintf(' '); end    if targetcount<100, fprintf(' '); end    if targetcount<10, fprintf(' '); end;    if uidx > 1      fprintf('event %-4d ttype %-8s - delays: ',evidx,EEG.urevent(evidx).type);     for k=1:npos      fprintf('(%d) ',ur_nbrs(targetcount,k));      if ur_nbrs(targetcount,k)<1000, fprintf(' '); end      if ur_nbrs(targetcount,k)<100, fprintf(' '); end      if ur_nbrs(targetcount,k)<10, fprintf(' '); end;      fprintf('%2.0f ',delays(targetcount,k));     end     if ~exist('NO_FIELD','var')       if cellfld == 0 % numeric field values        fprintf('field: %-5g - ',tfields(targetcount))        for k=1:npos         fprintf('%-5g ',nfields(targetcount,k));        end       elseif cellfld == 1  % cell array field values        if ischar(EEG.urevent(1).(field))         fprintf('field: %-5g -',tfields{targetcount})         for k=1:npos            fprintf('%-5g ',nfields{targetcount,k});         end % for        end % ischar       end % cellfield     end % ~NO_FIELD    end % uidx > 1    fprintf('\n');  end % debug_print end % istarget % %%%%%%%%%%%%%%%%% find next target event %%%%%%%%%%%%%%%%%%%%%% % evidx = evidx+1;      % continue event checkingend % event loop%%%%%%%%%% delete watibar %%%%%%%%%if ishandle(wb), delete(wb); end;if ~alltargs  fprintf('Returning info on the %d of %d target events that have epochs centered on them.\n',...                  targetcount-noepochs,targetcount);else  fprintf('Returning info on all %d target events (%d have epochs centered on them).\n',...                  targetcount,targetcount-noepochs);endif debug_print  fprintf('---------------------------------------------------\n');  fprintf('ur#   event   #  ttype targtype - delays (urnbr) ms\n');end%%%%%%%%%%%%%%% Truncate the output arrays %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%if targetcount > 0   targs   = [targs(1:targetcount) ur_trgs(1:targetcount) targepochs(1:targetcount)]; % 3-column output   ur_nbrs   = ur_nbrs(1:targetcount,:);   delays    = delays(1:targetcount,:);   epcenttargs = find(~isnan(targs(:,3))); % find targets that have an epoch centered on them   if ~alltargs      targs = targs(epcenttargs,:);      ur_nbrs = ur_nbrs(epcenttargs,:);      delays = delays(epcenttargs,:);   end   if ~exist('NO_FIELD','var')     if cellfld == 0       tfields = tfields(1:targetcount);       nfields = nfields(1:targetcount,:);     elseif cellfld == 1       tfields = tfields(1:targetcount);       nfields = nfields(1:targetcount,:);     end     if ~alltargs        tfields = tfields(epcenttargs,:);        nfields = nfields(epcenttargs,:);     end   else % NO_FIELD     tfields = [];     nfields = [];   end   ur_nbrtypes = ur_nbrtypes(1:targetcount,:);   if ~alltargs      ur_nbrtypes = ur_nbrtypes(epcenttargs,:);   endelse % return nulls if no targets found   if verbose     fprintf('eeg_context(): No target type events found.\n')   end   delays  = [];   targs   = [];   ur_nbrs = [];   tfields = [];   nfields = [];end 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -