image thumbnail

MLIB - toolbox for analyzing spike data

by

 

28 Jun 2012 (Updated )

Set of functions for the basic analysis of spike data from neurophysiological experiments

mraster.m
function [rastmat timevec] = mraster(trialspx,pre,post,varargin)
% function generates matrix for raster plot from cell array 'trialspx' generated by mpsth.m
% works with ms resolution
% 
% IMPORTANT: pre and post must be as large or larger than pre and post used to construct the PSTH w/ mpsth!!!
% 
% chart     if set, plots a raster
% 
% EXAMPLE
% [rastmat,timevec] = mraster(trialspx,1000,1000,'chart')       generates a raster display from -1000
%                                                               to +1000 ms and plots it
% 
% by Maik C. Stttgen, Feb 2011
%% read varargin
chart=0;
if nargin>3
  if strcmp(varargin{1},'chart')
    chart = 1;
  end
end
%% preallocate
rastmat = zeros(numel(trialspx),pre+1+post);
timevec = -pre:1:post;  
%% generate raster
for i = 1:numel(trialspx)
  rastmat(i,trialspx{i}+pre+1) = 1;
end
%% plot raster
if chart==1
  figure('name','peri-stimulus time histogram','units','normalized','position',[0.3 0.4 0.4 0.2])
  for i = 1:numel(trialspx)
    plot(timevec(rastmat(i,:)~=0),rastmat(i,rastmat(i,:)~=0)*i,'k.','MarkerSize',4),hold on
  end
  axis([-pre+10 post+10 0.5 numel(trialspx)+0.5])
  xlabel('time (ms)'),ylabel('trials')
end

Contact us