필터 지우기
필터 지우기

Binning data into 1 ms bins and count events

조회 수: 1 (최근 30일)
PAK
PAK 2018년 8월 24일
댓글: PAK 2018년 8월 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

채택된 답변

Image Analyst
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.
  댓글 수: 1
PAK
PAK 2018년 8월 30일
This worked really well! Thank you!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by