Can histogram bin edges and width be specified for the same histogram?

10 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Steven Lord
Steven Lord am 1 Okt. 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
ans = 1×7
0 0.0312 0.0625 0.1250 0.2500 0.5000 1.0000
h.BinWidth
ans = 'nonuniform'
  4 Kommentare
mackeca
mackeca am 4 Okt. 2021
I guess I hadn't thought of removing data after the fact, but that seems feasible. I'll give it a try and see if it will work for my purposes. Thank you for devoting some time to this.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 1 Okt. 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
  1 Kommentar
mackeca
mackeca am 4 Okt. 2021
Thank you for your answer, but I wasn't specific enough in my question. Sorry. I want to bin the data in uniform, narrower bins, but keep the same left edges of the bins, to allow the bins to skip over some data.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by