📄 rejstatepoch.m
字号:
% rejstatepoch() - reject bad eeg trials based a statistical measure. Can % be applied either to the raw eeg data or the ICA % component activity. This is an interactive function.%% Usage:% >> [ Irej, Irejdetails, n, threshold, thresholdg] = ...% rejstatepoch( signal, rej, 'key1', value1...);%% Inputs:% signal - 3 dimensional data array channel x points x trials % (instead of channels, one might also use independent% components).% rej - rejection array, one value per trial and per channel or% component (size channel x trials). % By default, values are normalized by this % function and trehshold is expressed in term of standard % deviation of the mean.%% Optional inputs:% 'plot' - ['on'|'off'] interactive mode or just rejection. % In the interactive mode, it plots the normalized % entropy of original signal (blue) and the limits % (red) (default:'on') % 'threshold' - percentage error threshold (default 1-0.25/nb_trials)% for individual trials of individual channel/component.% This treshold is expressed in term of standart % deviation from the mean (default 5).% 'global' - ['on'|'off'], also perform threshold on the global% measure (by default, the mean over all channel or% electrodes).% 'rejglob' - rejection array, one value per trials. Use this % argument when the global measure for all channels or% does not correspond to their mean.% 'thresholdg' - global threshold for the reunion of all channels% or components. By default, it is equal to 'threshold'.% 'normalize' - ['on'|'off'], normalize values before applying the % treshold. Default is 'on'. % 'plotcom' - sting command to plot single trials. Default % is none.% 'title' - title of the graph. Default is none.% 'labels' - labels for electrodes (array not cell).%% Outputs:% Irej - indexes of trials to be rejected% Irejdetails - array for rejected components or channel (nb_rejected x% nb_channel or nb_rejected x nb_components)% n - number of trials rejected% threshold - percentage error threshold % thresholdg - percentage error threshold for global rejection %% See also: eeglab()% Algorithm:% normalise the measure given as input and reject trials based on % an uniform distribution of the data%123456789012345678901234567890123456789012345678901234567890123456789012% Copyright (C) 2001 Arnaud Delorme, Salk Institute, arno@salk.edu%% This program is free software; you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation; either version 2 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program; if not, write to the Free Software% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA% userdata% gcf : plotsig - signal to plot in the pop_out window% pnts - number of points per epoch% Irej - rejection of trials% Irejelec - rejection of trials and electrodes% labels - labels for curves % plotwin : rej1 - rejection array (with all electrodes x trials)% rej2 - global rejection array (size trials)% thr1 - threshold (electrodes)% thr2 - threshold global% $Log: rejstatepoch.m,v $% Revision 1.8 2002/10/15 16:57:34 arno% waitfor for windows%% Revision 1.7 2002/08/20 22:25:34 arno% debug%% Revision 1.6 2002/08/12 22:19:34 arno% same%% Revision 1.5 2002/08/12 22:19:15 arno% update button and color%% Revision 1.4 2002/08/11 22:17:09 arno% color%% Revision 1.3 2002/08/07 23:17:24 arno% editing text%% Revision 1.2 2002/08/05 23:43:05 arno% update text%% Revision 1.1 2002/04/05 17:39:45 jorn% Initial revision%function [ Irej, Irejdetails, n, threshold, thresholdg] = rejstatepoch( signal, ... rej, varargin); % pnts, th_E, th_rejg, command, commandplot, typetitle, E, rejg);if nargin < 1 help rejstatepoch; return;end;if ~isstr( signal ) if nargin < 2 help rejstatepoch; return; end; if ~isempty( varargin ), g=struct(varargin{:}); else g= []; end; try, g.plot; catch, g.plot='on'; end; try, g.threshold; catch, g.threshold=5; end; try, g.thresholdg; catch, g.thresholdg=5; end; try, g.global; catch, g.global='on'; end; try, g.rejglob; catch, g.rejglob=[]; end; try, g.normalize; catch, g.normalize='on'; end; try, g.plotcom; catch, g.plotcom=''; end; try, g.title; catch, g.title=''; end; try, g.labels; catch, g.labels=''; end; g.rej = rej; clear rej switch lower(g.plot) case {'on', 'off'} ; otherwise disp('Error: Plot must be either ''on'' or ''off'''); return; end; switch lower(g.global) case {'on', 'off'} ; otherwise disp('Error: Global must be either ''on'' or ''off'''); return; end; switch lower(g.normalize) case {'on', 'off'} ; otherwise disp('Error: Normalize must be either ''on'' or ''off'''); return; end; if ~isstr(g.plotcom) disp('Error: Plotcom must be a string to evaluate'); return; end; if ~isstr(g.title) disp('Error: Title must be a string'); return; end; try, g.threshold*2; catch, disp('Error: Threhsold must be a number'); return; end; try, g.thresholdg*2; catch, disp('Error: Threhsoldg must be a number'); return; end; if length(g.threshold(:)) > 1 disp('Error: Threhsold must be a single number'); return; end; if length(g.thresholdg(:)) > 1 disp('Error: Threhsoldg must be a single number'); return; end; if ~isempty(g.rejglob) if length(g.rejglob) ~= size(g.rej,2) disp('Error: Rejglob must be have the same length as rej columns'); return; end; else switch lower(g.global), case 'on', g.rejglob = sum(g.rej,1); end; end; if size(signal,3) ~= size(g.rej,2) disp('Error: Signal must be have the same number of element in 3rd dimension as rej have columns'); return; end; if isempty(g.labels) for index = 1:size(g.rej,1) g.labels(index,:) = sprintf('%3d', index); end; if ~isempty(g.rejglob) g.labels(index+2,:) = 'g. '; end; end; switch lower(g.normalize), case 'on', g.rej = (g.rej-mean(g.rej,2)*ones(1, size(g.rej,2)))./ (std(g.rej, 0, 2)*ones(1, size(g.rej,2))); switch lower(g.global), case 'on', g.rejglob = (g.rejglob(:)-mean(g.rejglob(:)))./ std(g.rejglob(:)); end; end; switch lower(g.global), case 'off',g.rejglob = []; end; % plot the buttons % ---------------- try, icadefs; catch, GUIBUTTONCOLOR = [0.8 0.8 0.8]; BACKCOLOR = [0.8 0.8 0.8]; end; figure('color', BACKCOLOR); set(gcf, 'name', 'Rejectrials'); pos = get(gca,'position'); % plot relative to current axes set( gca, 'tag', 'mainaxis'); q = [pos(1) pos(2) 0 0]; s = [pos(3) pos(4) pos(3) pos(4)]./100; % allow to use normalized position [0 100] for x and y axis('off'); plotsig = sum(abs(signal(:,:)),1); set(gcf, 'userdata', { plotsig, size(signal, 2), [], [] }); % the two last arguments are the rejection % Create axis % ----------- h6 = axes('Units','Normalized', 'tag', 'Plotwin', 'Position',[-10 12 120 84].*s+q); title(g.title); set( h6, 'userdata', { g.rej g.rejglob g.threshold g.thresholdg g.labels }); % g.rej was put twice because it is used to compute the global entropy % CANCEL button % ------------- h = uicontrol(gcf, 'Style', 'pushbutton', 'string', 'Cancel', 'Units','Normalized','Position',... [-15 -6 15 6].*s+q, 'callback', 'close(gcf);', 'backgroundcolor', GUIBUTTONCOLOR); % Entropy component text and threshold % ------------------------------------ makebutton( 'Single-channel', 'Plotwin' , [3 -6 27 6].*s+q, [30 -6 15 6].*s+q, 3, g.threshold, GUIBUTTONCOLOR); makebutton( 'All-channel', 'Plotwin' , [50 -6 27 6].*s+q, [77 -6 15 6].*s+q, 4, g.thresholdg, GUIBUTTONCOLOR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -