


RASTERIZE Converts a list of events into a binary time series. RASTER = RASTERIZE(EVENTS) takes a vector EVENTS containing a list of indices and returns a binary vector RASTER with ones in locations given by EVENTS. E.g., RASTERIZE([1 5]) => [1 0 0 0 1]. RASTER = RASTERIZE(EVENTS,FS) specifies a sampling frequency FS; values in EVENTS are multiplied by FS and rounded to obtain indices into RASTER; e.g., RASTERIZE([0.1, 0.47], 10) => [1 0 0 0 1]. RASTERIZE(EVENTS) is equivalent to RASTERIZE(EVENTS,1). RASTER = RASTERIZE(EVENTS,FS,T) specifies a total time T, so that RASTER is length FS*T (events outside of this interval are ignored). The default value is the maximum of EVENTS. The array returned for RASTER is a row vector of type LOGICAL.


0001 function raster = rasterize(events, Fs, T) 0002 %RASTERIZE Converts a list of events into a binary time series. 0003 % RASTER = RASTERIZE(EVENTS) takes a vector EVENTS containing a list of 0004 % indices and returns a binary vector RASTER with ones in locations 0005 % given by EVENTS. E.g., RASTERIZE([1 5]) => [1 0 0 0 1]. 0006 % 0007 % RASTER = RASTERIZE(EVENTS,FS) specifies a sampling frequency FS; 0008 % values in EVENTS are multiplied by FS and rounded to obtain indices 0009 % into RASTER; e.g., RASTERIZE([0.1, 0.47], 10) => [1 0 0 0 1]. 0010 % RASTERIZE(EVENTS) is equivalent to RASTERIZE(EVENTS,1). 0011 % 0012 % RASTER = RASTERIZE(EVENTS,FS,T) specifies a total time T, so that 0013 % RASTER is length FS*T (events outside of this interval are ignored). 0014 % The default value is the maximum of EVENTS. 0015 % 0016 % The array returned for RASTER is a row vector of type LOGICAL. 0017 0018 %%%%% Deal with Fs & T ... 0019 if (nargin > 1), events = round(events*Fs); 0020 else, events = round(events); 0021 end 0022 0023 if (nargin > 2), len = Fs*prod(T); 0024 else, len = max(events); 0025 end 0026 0027 numevents = length(events); 0028 events(events>len) = []; 0029 if (length(events) < numevents), warning('Some events exceed raster grid.'); end; 0030 0031 numevents = length(events); 0032 events(events<=0) = []; 0033 if (length(events) < numevents), warning('Some events preceed raster grid.'); end; 0034 0035 %%%%% Make the logical raster 0036 raster = repmat(logical(0), 1, round(len)); 0037 raster(events) = 1;