필터 지우기
필터 지우기

creating a histogram in a specific way

조회 수: 2 (최근 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 CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by