histcounts do not provide a reasonable output
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Rik
il 26 Apr 2023
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?
Risposta accettata
Rik
il 26 Apr 2023
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')
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!