Binning data into 1 ms bins and count events
10 次查看(过去 30 天)
显示 更早的评论
Hi Everyone,
I have an experiment that is recorded over a timeperiod = 2.63610e+03 (in seconds). During my experiment, I was recording events. My output of that is a cell matrix, where each cell in the first row is equivalent to a list (in the form of a double matrix) of times where the event occurred.
How would I bin my time into 1 ms bins and then count how many events occur in each bin? I would like to calculate an average spike rate over the whole trial.
As always, thank you!
PK
0 个评论
采纳的回答
Image Analyst
2018-8-24
Try histogram() or histcounts().
First scan each cell in the first row of the cell array to get the max and min times so we can determine the edges for your histogram. Then scan again getting counts of events in each cell and add them in to the overall/master histogram. Something like (untested):
minTime = inf;
maxTime = -inf;
[rows, columns] = size(ca); % Get size of cell array
for col = 1 : columns
theseTimes = ca{1, col};
thisMin = min(theseTimes);
thisMax = max(theseTimes);
minTime = min(minTime, thisMin);
maxTime = max(maxTime, thisMax);
end
% Now construct edges
edges = minTime : 0.001 : (maxTime + 0.001);
% Now get histogram of all cells in first row.
allCounts = zeros(1, length(edges) - 1);
for col = 1 : columns
theseTimes = ca{1, col};
[counts, values] = histcounts(theseTimes, edges);
allCounts = allCounts + counts;
end
% Plot it
bar(edges(1:end-1), allCounts);
grid on;
Adapt/rename/fix as needed. Attach your data if you need more help.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!