문제

I would like to construct a histogram with unequal bins (intervals)..Matlab construct only histograms with equal bins as if it's a diagram..!!!

Please help me...thanks a lot!!

도움이 되었습니까?

해결책

Here's an example:

x = randn(100,1)*3;           %# some random data
e = [-10 -5 -3 -1 1 2 3 20];  %# edges of intervals:  e(i) <= x < end(i+1)
c = histc(x,e);               %# get count in each interval
bar(e, c, 'histc')            %# bar plot
set(gca, 'xlim',[e(1) e(end)])

output

다른 팁

2 solutions:

  1. Specify bin centers with the 2nd argument to hist.
  2. Specify bin Edges with with the 2nd argument to histc. This function takes some further processing since it does not generate the graph directly - follow the link for a usage example.

You could build your own histogram tool to create a custom histogram as you like.

  • Use histc to determine which bins each point falls inside.

  • Then use accumarray to count the number of elements in each bin.

  • Then use bar to draw bars of your chosen widths. Or simply create patches of the given sizes. Use patch for that.

Or more simply, just use hist.

hist(rand(1000,1),[0 .1 .3 .6 1])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top