Code for frequency of a number of bins
9 views (last 30 days)
Show older comments
Tam on 5 Feb 2023
Commented: Walter Roberson on 6 Feb 2023
I need to store into a variable the number of years (frequency) in which a certain number of incidents occured.
The code of the histogram plotted is below. Bin_centres is max/min values of freq(:,2), freq is the array. Column 1 are the years and column 2 are # of incidents.
I think I have to use hist.values and hist.BinEdges, but I don't know how to make that into a working code. I keep getting errors.
hist = histogram (freq(:,2), bin_centres)
Walter Roberson on 6 Feb 2023
"Bin_centres is max/min values of freq(:,2),"
freq(:, 2) is a vector. It has a single max and a single min. So you only have 1+1=2 bin boundaries. histogram puts data exactly equal to the last value into the previous bin so N edges results in (N-1) bins. 2 edges therefore creates exactly one bin. The result would be to count all of the values between the min and max, inclusive, which of course would just be the same as counting the non-nan inputs.
Sulaymon Eshkabilov on 6 Feb 2023
This is how you can plot hist() or histogram(), e.g.:
D = round(100*(randn(1000, 1)),0)+375;
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!