Code covered by the BSD License  

Highlights from
Normalized histogram

4.0

4.0 | 6 ratings Rate this file 212 Downloads (last 30 days) File Size: 1.66 KB File ID: #22802
image thumbnail

Normalized histogram

by Arturo Serrano

 

28 Jan 2009

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 (10000, 1);
      [xo,no] = histnorm(data, 101, 'plot');
      hold on
      plot (no, normpdf(no), 'r');
      hold off

  See also: HIST.

  Copyright 2009 DWTFYW.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
20 Feb 2009 Darcy Sabatino

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

16 Nov 2009 abdelhamid alhassi

thanks very helpful

25 Feb 2010 Ian Baldwin

very useful

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 ?

17 Jun 2010 Gustavo  
03 Oct 2010 Anne Calder

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

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

13 Oct 2010 Anne Calder

Thank you! Works perfect!

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

18 Aug 2011 Bob

disregard above comment about the mean...

04 Sep 2011 Flavio Prattico

Great!!!

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
histogram Arturo Serrano 28 Jan 2009 11:01:27
normalized Arturo Serrano 28 Jan 2009 11:01:27
histogram D L 06 Feb 2010 01:09:53
normalized Martin 30 Jan 2012 11:21:25
histogram Martin 30 Jan 2012 11:21:28
histogram mojtaba 05 Feb 2012 07:20:32
normalized Rosalba Z 15 Feb 2012 20:16:41
histogram Rosalba Z 15 Feb 2012 20:16:42

Contact us at files@mathworks.com