function spikeraster(spikes, tmax)
% Display a spike raster of the spike times given in spikes.
%
% spikeraster(spikes, tmax)
%   spikes: a cell array of vectors of spike times in seconds
%   tmax: plot spike raster upto tmax seconds

ntrials = length(spikes);
for k = 1:ntrials
    times = spikes{k};
    times = times(times<tmax);
    if tmax < 1.5
        times = 1000.0*times; % conversion to ms
    end
    for i = 1:length( times )
      line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k' ); 
    end
end
if tmax < 1.5
    xlabel( 'Time [ms]' );
    xlim([0.0 1000.0*tmax]);
else
    xlabel( 'Time [s]' );
    xlim([0.0 tmax]);
end
ylabel( 'Trials');
ylim( [ 0.3 ntrials+0.7 ] )

end

