Home > data-analysis > manip > event > event_duration_hist.m

event_duration_hist

PURPOSE ^

A histogram of the duration of the events in an event variable

SYNOPSIS ^

function [histogram bins] = event_duration_hist(event_var, bins, args)

DESCRIPTION ^

 A histogram of the duration of the events in an event variable

   USAGE:
   [histogram bins] = event_duration_hist(event_var)
       Returns the histogram or the durations, and a list of the bin
       centers used in the calculation.

   histogram = event_duration_hist(event_var, bins)
       Returns the histogram created by using the numbers in BINS as bin
       centers.
 
   histogram = event_duration_hist(event_var, bins, 'centers')
       Returns the histogram created by using the numbers in BINS as bin
       centers.
 
   histogram = event_duration_hist(event_var, bins, 'thresholds')
       Returns the histogram created by using the numbers in BINS as bin
       thresholds.

   See also: HIST

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [histogram bins] = event_duration_hist(event_var, bins, args)
0002 % A histogram of the duration of the events in an event variable
0003 %
0004 %   USAGE:
0005 %   [histogram bins] = event_duration_hist(event_var)
0006 %       Returns the histogram or the durations, and a list of the bin
0007 %       centers used in the calculation.
0008 %
0009 %   histogram = event_duration_hist(event_var, bins)
0010 %       Returns the histogram created by using the numbers in BINS as bin
0011 %       centers.
0012 %
0013 %   histogram = event_duration_hist(event_var, bins, 'centers')
0014 %       Returns the histogram created by using the numbers in BINS as bin
0015 %       centers.
0016 %
0017 %   histogram = event_duration_hist(event_var, bins, 'thresholds')
0018 %       Returns the histogram created by using the numbers in BINS as bin
0019 %       thresholds.
0020 %
0021 %   See also: HIST
0022     
0023 durations = event_var(:, 2) - event_var(:, 1);
0024 
0025 if nargin < 2
0026     [histogram bins] = hist(durations);
0027 elseif nargin == 2
0028     [histogram bins] = hist(durations, bins);
0029 else
0030     if strcmp(args, 'centers')
0031         [histogram bins] = hist(durations, bins);
0032     elseif strcmp(args, 'thresholds')
0033         histogram = zeros(1, length(bins));
0034 
0035         for i = 2:length(bins)
0036             lower = bins(i-1);
0037             upper = bins(i);
0038             x_within = durations >= lower & durations < upper;
0039             histogram(i-1) = sum(x_within);
0040         end
0041 
0042         x_within = durations >= upper;
0043         histogram(end) = sum(x_within);
0044     end
0045 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005