📄 eeg_eventhist.m
字号:
%% eeg_eventhist() - return or plot histogram of event or urevent field values. % If NO output args, plots the histogram. If the field values % are not numbers or strings, no histogram is computed.% Usage:% >> [vals] = eeg_eventhist(Event,'field'); % returns the field values % >> figure; eeg_eventhist(Event,'field',bins); % plots the histogram% >> [vals,histNs,bins] = eeg_eventhist(Event,'field',bins); % no plot%% Inputs:%% Event - an EEGLAB EEG.event or EEG.urevent structure % 'field' - string containing the name of a field in the Event structure% bins - optional number of bins to use, else vector of bin edges {default: 10}% If event field values are strings, this argument is not used.%% Outputs:%% vals - numeric, struct, or cell array vector of field values for each event% in the input event order% histNs - numbers of events in the histogram bins% outbins - if numeric values, a one-column matrix giving bin edges of the [low,high) bins. % Else, if string values, cell array containing the string associated with each bin.%% Example:% >> [vals,histNs,bins] = eeg_eventhist(EEG.event,'type');% %% % Returns cell array of event-type strings, numbers of each event type, % % and event type strings, in alphabetic order. No plot produced.%% See also: pop_eventstat(), signalstat(), pop_signalstat().%% Author: Scott Makeig, SCCN, Institute for Neural Computation, UCSD, March 26, 2004%function [vals,histNs,outbins] = eeg_eventhist(Event,field,bins)if nargin < 2 help eeg_eventhist returnendif nargin < 3 bins = 10;endif isempty(Event) error('Event structure is empty');endif ~isfield(Event,field) error('named field is not an Event field')endfield1 = getfield(Event(1),field);if ischar(field1) IS_CHAR = 1;elseif isstruct(field1) IS_STRUCT = 1;else IS_NUM = 1;endif exist('IS_NUM') vals = zeros(length(Event),1);elseif exist('IS_CHAR') vals = cell(length(Event),1);elseif exist('IS_STRUCT') vals = repmat(field1,length(Event),1);else error('unknown field type')endif exist('IS_NUM') for k=1:length(Event) vals(k) = getfield(Event(k),field); endelse for k=1:length(Event) vals{k} = getfield(Event(k),field); endendif nargout == 1 | exist('IS_STRUCT') return % return vals only, no histogram end%if exist('IS_NUM') %%%%%%%%%%%%%%%% numeric values histogram %%%%%%%%%%%%%%%%%%%%%%% if numel(bins) == 1 if bins < 3 error('number of bins must be > 2'); end mn = mean(vals); stdev = std(vals); binsout = zeros(bins,1); fl2 = floor(bins/2); for k = -1*fl2:ceil(bins/2) binsout(k+fl2+1) = mn+k*stdev; end binsout(1) = -inf; binsout(end) = inf; histNs = histc(vals,binsout); histNs = histNs(1:end-1); else % accomodate specified bin edges histNs = histc(vals,bins); histNs = histNs(1:end-1); end outbins = binsout; if nargout == 0 h = bar(histNs,'histc'); end%else % exist('IS_CHAR') %%%%%%%%%%%% string values histogram %%%%%%%%%%%%%%%%%%%%%%% outbins = unique(vals); histNs = zeros(length(outbins)-1,1); for k=1:length(outbins) histNs(k) = sum(ismember(vals,outbins{k})); end if nargout == 0 h = bar(histNs,1); % set(h,'xticklabel',outbins); % ??? NEEDS MORE WORK - CANT TEST FROM HOME endendreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -