Plot occurrences of values with bin edges, by using "histcounts" and "plot" functions
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Steven Lord
le 8 Mar 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Annotations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!