creating a histogram in a specific way

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by