histcounts do not provide a reasonable output
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello everyone,
I have a 2D matrix, idx_matr_resh_single_tr_non_bool, size 15000x1, logical values, and I need to count the occurence of events within discrete time bins. The zeros represent no events, while ones represent events.
After performing this string of code:
tbin_edges = 60;
spikes_prova = histcounts(bool_matr,tbin_edges);
I get a weird result: it produce a matrix 60x1. After opening it, the total number of rows (15000) is displayed in the first row, then the array is filled with zeros. A couple of time I ended up with 14998 displayed in the first row and 2 in the last row.
I know, after computing them in the same matrix using sum function and after replacing logical with double, that there are a lot of events in this matrix.
I tried logical and double as well. I have no clue what's going on here
댓글 수: 2
Rik
2023년 4월 26일
It doesn't seem like this function is doing what you think it is doing. If you want to count events in time bins, you need to use a different function. This function will not look at your variable names and do what you mean, it will do exactly what you tell it to do.
So why don't you explain what kind of result you want? To you want a sliding window counting all events? To you want to split the array in chunks of 60 elements and count the number of events?
채택된 답변
Rik
2023년 4월 26일
With Matlab you generally don't have to be confused about functions. The documentation is one of the major advantages of Matlab over competing products.
S=load('bool_matr.mat');data = S.idx_matr_resh_single_tr_non_bool;
To calculate the count per chunk you can use reshape and sum (which will automatically convert to double):
counts_per_chunk = sum(reshape(data,[],60),2)
To calculate a sliding window sum, you can use movsum, but I prefer a convolution:
sliding_window_counts = conv(data,ones(1,60),'same')
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!