Code covered by the BSD License  

Highlights from
Normalized histogram

4.25

4.2 | 13 ratings Rate this file 114 Downloads (last 30 days) File Size: 1.66 KB File ID: #22802
image thumbnail

Normalized histogram

by

 

28 Jan 2009 (Updated )

Same as histogram, but the area sum is 1.

| Watch this File

File Information
Description

HISTNORM Histogram normalized
  [...] = HISTNORM(...) works like HIST, but the frequency is normalized so that area sum is 1.

  Bonus usage!
  [...] = HISTNORM(..., 'plot') plots and returns the output arguments. Be sure 'plot' is the last argument.

  Example:
      data = randn(1)+randn(1)*randn (10000, 1);
      [xo,no] = histnorm(data, 101, 'plot');
      hold on
      plot (no, normpdf(no, mean(data), std(data)), 'r');
      hold off

  See also: HIST.

  Copyright 2009 DWTFYW.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (22)
22 Nov 2014 ?  
10 Jul 2013 R

it work fantastic:)how could we use histnorm to calculate normalized histogram for hsv histogram

10 Jul 2013 R  
10 Jul 2013 R  
26 Apr 2013 Damien

thanks!!!

25 Mar 2013 arnold

nice one, thanks!

22 Mar 2013 Arturo Serrano

The *area* must sum up to 1.
Thanks for rating!

21 Mar 2013 Linpeng

The columns sum up to 10 instead of 1. Any ideas?

13 Mar 2013 Arturo Serrano

*Why* is not working? I don't see any problems. Maybe if you give some clues, we can help.

12 Mar 2013 Bernoulli Lizard

This does not work. The height of my bins is on the order of 10^4. What is wrong?

22 Jun 2012 Shinobue111

Fantastic :)

04 Sep 2011 Flavio Prattico

Great!!!

18 Aug 2011 Bob

disregard above comment about the mean...

18 Aug 2011 Bob

Doesn't seem to work with non-zero mean data sets. I found that the code below works better. It can not handle the case where you specify your own bin widths. But it can handle a matrix of data.
e.g.: histnorm([randn(1e3,1) randn(1e3,1)+8],50)

function varargout = histnorm(varargin)

len = size(varargin{1});
n = len(2);
[xo,no] = hist (varargin{:});
binwidths = diff(no);
xonorm = xo/sum (xo .* (binwidths(1)*ones(size(xo))))*n;
bar(no,xonorm);

13 Oct 2010 Anne Calder

Thank you! Works perfect!

04 Oct 2010 Arturo Serrano

Hi Anne,
you can change the colors by setting properties from the matlab command window. This should does the trick:

>> set (findobj (gca, 'type', 'patch'), 'edgecolor', [0.5 0.5 0.5], 'facecolor', [0.1 0.1 0.1]);

Edgecolor and facecolor values are the RGB values for bin colors (you can use letters also as plot does).

03 Oct 2010 Anne Calder

Super useful... was wondering if you can change the colors in the bins. This isn't working for me.

17 Jun 2010 Gustavo  
05 Mar 2010 Shahzad Bhatti

It didn't work for me. It is giving same histogram as does hist ... I mean it is not normlizing !!!

@ Author - Any idea - what i am doing wrong ?

25 Feb 2010 Ian Baldwin

very useful

16 Nov 2009 abdelhamid alhassi

thanks very helpful

20 Feb 2009 Darcy Sabatino

Very helpful. The histnorm() function is virtually as easy as the hist() function.

Updates
22 Mar 2013

Updated the example.

Contact us