views:

533

answers:

3

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!!

+2  A: 

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])
woodchips
+4  A: 

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.
Ofek Shilon
+4  A: 

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)])

alt text

Amro
Thanks a lot...i used your solution to build a function for my context of study ..
yasmine

related questions