title: How to plot PDF and CDF for a normal distribution in matlab
body: <p>I couldn't find a function in matlab that implement gets mean and standard deviation of normal distribution and plot its <a href="http://en.wikipedia.org/wiki/Probability_density_function" rel="nofollow noreferrer">PDF</a> and <a href="http://en.wikipedia.org/wiki/Cumulative_distribution_function" rel="nofollow noreferrer">CDF</a>. </p>
  
  <p>I am afraid the two functions I have implemented bellow are missing something, since I get maximal value for <code>pdfNormal</code> which is greater than 1.</p>
  
  <pre><code>function plotNormPDF(u,s,color)
      mu = u; 
      sigma = s; 
      x = (mu - 5 * sigma) : (sigma / 100) : (mu + 5 * sigma); 
      pdfNormal = normpdf(x, mu, sigma);
      string = 'the maximal pdfNormal is';
      string = sprintf('%s :%d', string,max(pdfNormal));
      disp(string)
      plot(x, pdfNormal/max(pdfNormal),color); 
  end
  </code></pre>
  
  <p>And for the CDF norm</p>
  
  <pre><code>function plotNormCDF(u,s,color)
      mu = u; 
      sigma = s; 
      x = (mu -  5*sigma) : (sigma / 100) : (mu + 5*sigma); 
      pdfNormal = normpdf(x, mu, sigma);
      plot(x,cumsum(pdfNormal)./max(cumsum(pdfNormal)),color)
  end
  </code></pre>
  
  <p>Here is an example for using both:</p>
  
  <pre><code>plotNormCDF(0.2, 0.1,'r')
  plotNormPDF(0.2, 0.1,'r')
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/eK3BG.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/c74vX.png" alt="enter image description here"></p>