Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to construct unequal width histograms with Matlab?

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

like image 341
yasmine Avatar asked Mar 04 '10 12:03

yasmine


People also ask

Can histograms have different bin widths?

Most histograms use bin widths that are as equal as possible, but it is also possible to use unequal bin widths (see the 'Variable bin widths' section of Histogram). A recommended strategy is to size bins so the number of values they contain is approximately equal.

Do histogram bins need to be equal?

The bins (intervals) must be adjacent and are often (but not required to be) of equal size. To roughly assess the probability distribution of a given variable by depicting the frequencies of observations occurring in certain ranges of values.

How do you change the number of bins in a histogram in Matlab?

Description. N = morebins( h ) increases the number of bins in histogram h by 10% (rounded up to the nearest integer) and returns the new number of bins. For bivariate histograms, this increases the bin count in both the x and y directions.


2 Answers

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

like image 127
Amro Avatar answered Nov 05 '22 08:11

Amro


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.
like image 25
Ofek Shilon Avatar answered Nov 05 '22 09:11

Ofek Shilon