Plot occurrences of values with bin edges, by using "histcounts" and "plot" functions
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I have 1000 normally distributed random numbers (with mean = 3 and standard deviation = 10):
X = normrnd(3,10,[1,1000])
I want to partition the X values into 100 bins, and return the count in each bin (i.e. the occurrence of values within each bin), as well as the bin edges:
[n,bin_edges] = histcounts(X,100);
Then, I want to plot the count in each bin together with the values of the bin edges.... Should I (maybe) use the average value of two edges, i.e. the, or is there any other way to plot the count of my values with the bin edges?
plot(bin_edges(1:100),n); % this is not correct, because I plot the left edge for each occurrence of values
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 8 Mär. 2022
Why not just use histogram?
X = normrnd(3,10,[1,1000]);
h = histogram(X, 100);
c = h.BinCounts;
e = h.BinEdges;
for whichBin = 1:5
fprintf("In bin %d [%g, %g) there were %d elements.\n", ...
whichBin, e(whichBin:whichBin+1), c(whichBin));
end
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!