From 16f19ebf5ecb436224a98ed8a12530603f266c73 Mon Sep 17 00:00:00 2001 From: ilandau <45141477+ilandau@users.noreply.github.com> Date: Fri, 15 May 2020 13:03:36 +0300 Subject: [PATCH] Update psthRasterAndCounts.m Updated to the up-to-date matlab function histcounts. It receives an array of bin-edges (together with the data), and returns those same bin-edges. The returned variable bins is an array of bin-centers. --- analysis/psthRasterAndCounts.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/analysis/psthRasterAndCounts.m b/analysis/psthRasterAndCounts.m index 85d5646..7489837 100644 --- a/analysis/psthRasterAndCounts.m +++ b/analysis/psthRasterAndCounts.m @@ -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. @@ -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 @@ -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)); \ No newline at end of file +spikeCounts(ismember(1:nRanges,wr)) = diff(find(diff([0 wr nRanges+1])>0));