Home > General-Functions > SUGR > General > Plots > sugr_plot_histogram_density.m

sugr_plot_histogram_density

PURPOSE ^

% plots histogrqam with theoretical density function

SYNOPSIS ^

function sugr_plot_histogram_density(x,pdf,npar,A,B,C)

DESCRIPTION ^

% plots histogrqam with theoretical density function

 x     = data vector
 pdf   = expected density
 npar  = number of parameters for density (0,1,2,3)
 A,B,C = parameters (possibly B is not set)
 
 assumes figure with hold on is open.

 Wolfgang Förstner 3/2017
 wfoerstn@uni-bonn.de

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %% plots histogrqam with theoretical density function
0002 %
0003 % x     = data vector
0004 % pdf   = expected density
0005 % npar  = number of parameters for density (0,1,2,3)
0006 % A,B,C = parameters (possibly B is not set)
0007 %
0008 % assumes figure with hold on is open.
0009 %
0010 % Wolfgang Förstner 3/2017
0011 % wfoerstn@uni-bonn.de
0012 
0013 function sugr_plot_histogram_density(x,pdf,npar,A,B,C)
0014 
0015 % number of samples
0016 N = length(x);
0017 
0018 %prepare plot
0019 
0020 N_bin  = floor(sqrt(N));        % number of bins
0021 [NN,r] = hist(x,N_bin);         % calculate histogram
0022 
0023 %% plot histogram
0024 bar(r,NN)                             
0025 
0026 %% plot expected density
0027 
0028 % range of histogram
0029 range = abs(r(N_bin)-r(1))*N_bin/(N_bin-1);                       
0030 switch npar
0031     case 0
0032         plot(r,N_bin*range*pdf(r),'-r','LineWidth',4);
0033     case 1
0034         plot(r,N_bin*range*pdf(r,A),'-r','LineWidth',4);
0035     case 2
0036         plot(r,N_bin*range*pdf(r,A,B),'-r','LineWidth',4);
0037     case 3
0038         plot(r,N_bin*range*pdf(r,A,B,C),'-r','LineWidth',4);
0039 end
0040 xlim([r(1),r(N_bin)]);
0041 ylim([0,max(NN)*1.1]);
0042 xlabel('x');ylabel('$\propto p_x(x)$')
0043 title(['Histogram of the sample with ',num2str(N_bin),' bins, overlayed with its probability density.'])
0044 
0045 
0046

Generated on Sat 21-Jul-2018 20:56:10 by m2html © 2005