# Does anyone know how to overlay a equalized CDF plot with equalized histogram in matlab?

I am willing to overlay a equalized cdf with equalized histogram in matlab. But it's really hard to find any recommends. so if you can, would you please let me know about that?

• Maybe you want to overlay the PDF with the histogram? – Gilles Oct 23 '14 at 9:11
• No I want to overlay plot with cdf. – Carter Oct 23 '14 at 13:48

You can use 'hold on' with a histogram:

[n,x]=hist(rand(1,100),20);  % find the histogram
bar(x,n./sum(n))             % plot normalized histogram
hold on                      % don't delete current plot
plot([0 1],[0.1 0.1])        % plot a uniform pdf
axis([0 1 0 0.12])           % make room around the plot


Another example using a normal distribution, which shows how to normalize the histogram so that its area is one:

r=randn(1,1000);      % normal random variable
[n,x]=hist(r,25);
delta=x(2)-x(1);
n=n./(delta*sum(n));  % n is normalized so that its area is 1
bar(x,n)
hold on
d=-4:0.1:4;
plot(d,(1/sqrt(2*pi))*exp(-(d.*d)./2),'r')  % plot of the normal pdf

• Thanks but it does not realized with equalized cdf. Where can I find equalized CDF in your code? – Carter Oct 23 '14 at 3:51
• Even it was just made by hard plot and not equalized CDF. – Carter Oct 23 '14 at 4:16
• Your question is how to overlay a plot with a histogram, not how to obtain an "equalized CDF" (which I assumed is just a PDF), which is an entirely different question. In my answer, I'm simulating a uniform random variable (with rand in the first line), and I plot a uniform PDF in line 4. – MBaz Oct 23 '14 at 13:27
• Thanks. this looks like so. I need make to another post same subject. – Carter Oct 23 '14 at 13:47
• @user1917217: I've added another example that shows more clearly how to normalize the histogram to obtain a probability density function (pdf). – MBaz Oct 23 '14 at 13:50