creating a histogram in a specific way

7 ビュー (過去 30 日間)
alex
alex 2011 年 12 月 14 日
hi, I want to make a histogram that gets a vector with values from the group (0 1 10 100, and creates a histogram that has one bin for each of those values and has the axis of x also sorted only for those values. I tried few things and nothing seems to work. I wand the bins in the same width.

採用された回答

the cyclist
the cyclist 2011 年 12 月 14 日
r = [0 0.1 0.2 0.3 1 2 3 10 20 30 40 50 60 70 80 90];
bins = [0 1 10 100];
count=hist(r,bins)
figure
bar(bins,count)
set(gca,'XTick',bins)
OR
r = [0 0.1 0.2 0.3 1 2 3 10 20 30 40 50 60 70 80 90];
bins = [0 1 10 100]
count=hist(r,bins)
figure
bar(1:4,count)
set(gca,'XTickLabel',bins)
  1 件のコメント
the cyclist
the cyclist 2011 年 12 月 14 日
If you use either of these solutions, do be aware of the issue that Sean brings up, which is whether you want the binning itself to be on a log scale. The binning in my solution is on a linear scale (even in the solution in which I display the results on what is essentially a log scale).

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

その他の回答 (1 件)

Sean
Sean 2011 年 12 月 14 日
Are you trying to bin on a log scale or are you trying to bin to arbitrary values?
If you are trying to do the first, you might try taking the log10() of all your input values and binning them linearly (i.e. less than 1 is negative, 1-9.9999 is is 0-1, 10-99.9999 is 1-2, etc.) You could round the values to fall into whichever bin you wanted.
  1 件のコメント
Dr. Seis
Dr. Seis 2011 年 12 月 14 日
Agreed... and then holding the bin "width" the same would make more sense.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by