问题
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!!
回答1:
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)])
回答2:
2 solutions:
- Specify bin centers with the 2nd argument to hist.
- 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.
回答3:
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])
来源:https://stackoverflow.com/questions/2379230/how-to-construct-unequal-width-histograms-with-matlab