Can histogram bin edges and width be specified for the same histogram?
38 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mackeca
el 1 de Oct. de 2021
Comentada: mackeca
el 4 de Oct. de 2021
I'd like to bin data for analysis, and then repeat the analysis with differing time windows/durations. In this case, I'm analyzing neuronal spike times after binning the data like this:
edges=0:0.5:116.5;
binnedspks=histogram(sortedspikes,edges)
But there doesn't seem to be a way to specify that the data be binned in thinner bins after edges are specified, or vice versa, which would require each successive bin to skip over some of the data.
I've tried a few combinations of things like this but the edges input just seems to overwrite the width:
histogram(sortedspikes,'BinWidth',0.5,'BinEdges',edges)
0 comentarios
Respuesta aceptada
Steven Lord
el 1 de Oct. de 2021
The edges input is not required to be a uniformly spaced vector.
x = rand(1, 1e5);
E = [0 2.^(-5:0)];
h = histogram(x, E, 'Normalization', 'probability');
xticks(E)
xticklabels(["0", "2^{" + string(-5:0) + "}"])
You can see that about half the numbers are in the bin from 1/2 to 1, about a quarter in the bin from 1/4 to 1/2, etc. You can also see that the BinEdges are not uniformly spaced, and the histogram will tell you that if you ask for the width of the bins.
h.BinEdges
h.BinWidth
4 comentarios
Más respuestas (1)
Image Analyst
el 1 de Oct. de 2021
You can specify the bin widths
for k = 1 : 20
binWidth = k / 10; % Whatever...
edges = 0 : binWidth : 116.5;
counts = histcounts(sortedspikes, edges)
bar(edges, counts);
xlabel('Value');
ylabel('Count');
grid on;
drawnow;
pause(1); % Wait a short time so you can see the histogram.
end
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!