0
$\begingroup$

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?

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

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
$\endgroup$
  • $\begingroup$ Thanks but it does not realized with equalized cdf. Where can I find equalized CDF in your code? $\endgroup$ – Carter Oct 23 '14 at 3:51
  • $\begingroup$ Even it was just made by hard plot and not equalized CDF. $\endgroup$ – Carter Oct 23 '14 at 4:16
  • $\begingroup$ 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. $\endgroup$ – MBaz Oct 23 '14 at 13:27
  • $\begingroup$ Thanks. this looks like so. I need make to another post same subject. $\endgroup$ – Carter Oct 23 '14 at 13:47
  • $\begingroup$ @user1917217: I've added another example that shows more clearly how to normalize the histogram to obtain a probability density function (pdf). $\endgroup$ – MBaz Oct 23 '14 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.