フィルターのクリア

how to construct histogram with certain bin size?

11 ビュー (過去 30 日間)
Hydro
Hydro 2018 年 8 月 23 日
コメント済み: Hydro 2018 年 8 月 23 日
Hello,
I am constructing histogram with certain bin size. I have around 200000 packages that range in price from 0 - 3824400. I want to place packages that cost 0-20000 in twenty bins with step 1000. Packages that cost more than 20000 should be placed into the last bin# 21 altogether. below is my code so far, how the histogram is pretty weird. I want to see a histogram something like attached. I appreciate any insight
Packages=randi([0 3824400],200000,1);
edges=[0:1000:20000 3824400];
h = histogram(Packages,edges);
  2 件のコメント
Geoff Hayes
Geoff Hayes 2018 年 8 月 23 日
Hydro - please clarify what you mean by the histogram is pretty weird. Can you show us what it looks like? Is the data not being distributed across the 21 bins as expected? Presumably you have actual package data and are not relying on randi to generate your data for you..
Hydro
Hydro 2018 年 8 月 23 日
編集済み: Hydro 2018 年 8 月 23 日

Hello Geoff,

Attached is what i am getting. I want all my data > 20000 in the last bin (not occupying the entire x-axis). I can not see the count of my pacakges price above a certain price (base on bin).

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

採用された回答

Rik
Rik 2018 年 8 月 23 日
編集済み: Rik 2018 年 8 月 23 日
If you want strange bins, you'll have to do some work yourself (I changed the number generation btw). The labels are also not too difficult to generate.
Packages=randi([0 44000],200000,1);
edges=[0:1000:20000 inf];
labels=cell(numel(edges)-1,1);
labels{1}=sprintf('<%d',edges(2));
for n=2:(numel(labels)-1)
labels{n}=sprintf('%d-%d',edges(n)+1,edges(n+1));
end
labels{end}=sprintf('>%d',edges(end-1));
[N,edges] = histcounts(Packages,edges);
centers=edges(1:(end-1))+diff(edges(1:2));
bar(centers,N)
xticks(centers)
set(gca,'XTickLabels',labels)
set(gca,'XTickLabelRotation',60)
  1 件のコメント
Hydro
Hydro 2018 年 8 月 23 日
Hello Rik,
Many thanks, it worked. hydro

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

その他の回答 (0 件)

カテゴリ

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