Code for frequency of a number of bins

4 ビュー (過去 30 日間)
Tam
Tam 2023 年 2 月 5 日
コメント済み: Walter Roberson 2023 年 2 月 6 日
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 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 5 日
Bin_centres is max/min values of freq(:,2)
That would lead to only one bin.
Walter Roberson
Walter Roberson 2023 年 2 月 6 日
"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.

サインインしてコメントする。

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023 年 2 月 6 日
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 件のコメント
Tam
Tam 2023 年 2 月 6 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by