This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/pointprocesses/code/rasterplot.m

35 lines
1.1 KiB
Matlab

function rasterplot(spikes, tmax)
% Display a spike raster of the spike times given in spikes.
%
% rasterplot(spikes, tmax)
%
% Arguments:
% spikes: a cell array of vectors of spike times in seconds
% tmax: plot spike raster up to tmax seconds
spiketimes = [];
trials = [];
ntrials = length(spikes);
for k = 1:ntrials
times = spikes{k};
times = times(times<tmax);
% (x,y) pairs for start and stop of stroke
% plus nan separating strokes:
spiketimes = [spiketimes, ...
[times(:)'; times(:)'; times(:)'*nan]];
trials = [trials, ...
[ones(1, length(times)) * (k-0.4); ...
ones(1, length(times)) * (k+0.4); ...
ones(1, length(times)) * nan]];
end
% convert matrices into simple vectors of (x,y) pairs:
spiketimes = spiketimes(:);
trials = trials(:);
% plotting this is lightning fast:
plot(spiketimes, trials, 'k')
xlabel('Time [s]');
xlim([0.0 tmax]);
ylabel('Trials');
ylim([0.3 ntrials+0.7]);
end