Code for frequency of a number of bins

10 visualizaciones (últimos 30 días)
Tam
Tam el 5 de Feb. de 2023
Comentada: Walter Roberson el 6 de Feb. de 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)
  2 comentarios
Walter Roberson
Walter Roberson el 5 de Feb. de 2023
Bin_centres is max/min values of freq(:,2)
That would lead to only one bin.
Walter Roberson
Walter Roberson el 6 de Feb. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 6 de Feb. de 2023
This is how you can plot hist() or histogram(), e.g.:
D = round(100*(randn(1000, 1)),0)+375;
figure
hist(D, max(D))
figure
histogram(D, min(D))
figure
histfit(D, max(D))
  1 comentario
Tam
Tam el 6 de Feb. de 2023
Thank you, but I just need a variable that stores the frequency of each bin. I've already plotted the graph. I don't know if I explained it properly.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots 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!

Translated by