Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update psthRasterAndCounts.m #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions analysis/psthRasterAndCounts.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%
% Notes on outputs:
% - psth can be plotted with plot(bins, psth);
% bins is an array of bin-centers, psth is the array of counts associated with each bin
% - rasters can be plotted with plot(rasterX, rasterY);
% - spikeCounts is nEvents x 1, where each entry is the number of spikes
% that occurred within the window around that event.
Expand All @@ -28,8 +29,9 @@
stRelToEvent = stIn-eventTimes(wr); % subtract the event time corresponding to each spike


[psth,bins] = hist(stRelToEvent, [window(1):psthBinSize:window(2)]);

edges = window(1):psthBinSize:window(2);
[psth, edges] = histcounts(stRelToEvent, edges);
bins = edges(1:end-1) + psthBinSize/2;

[rasterX,yy] = rasterize(stRelToEvent);
rasterY = yy+reshape(repmat(wr,3,1),1,length(wr)*3); % yy is of the form [0 1 NaN 0 1 NaN...] so just need to add trial number to everything
Expand All @@ -41,4 +43,4 @@
% spikes of the next. The distance between these breaks are the spike counts
% Find gives you the indices of these breaks, outer diff computes how many in
% each.
spikeCounts(ismember(1:nRanges,wr)) = diff(find(diff([0 wr nRanges+1])>0));
spikeCounts(ismember(1:nRanges,wr)) = diff(find(diff([0 wr nRanges+1])>0));