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!