title: How to smooth data in matlab without using method from any toolkit
body: <p>I am trying to smooth some measurement data in Matlab and I think so, I am missing something. I wrote my own code to create the Gaussian window. However rest of code is copied from <a href="http://www.mathworks.com/matlabcentral/newsreader/view_thread/272556" rel="nofollow noreferrer">this</a> link:</p>
  
  <pre><code>% Generate sample data.
  vector = 5*(1+cosd(1:3:180)) + 2 * rand(1, 60);
  hist (vector)  ;
  plot(vector, 'r-', 'linewidth', 3);
  set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
  
  % Construct blurring window.
  windowWidth = int16(11);
  halfWidth = windowWidth / 2 ;
  gaussFilter = Gaussain (-5:5, 0, 1 ) ;
  gaussFilter = gaussFilter / sum(gaussFilter); % Normalize.
  
  % Do the blur.
  smoothedVector = conv(vector(halfWidth:end-halfWidth), gaussFilter) ;
  
  % plot it.
  hold on;
  plot(smoothedVector, 'b-', 'linewidth', 3);
  </code></pre>
  
  <p>Please help me correct my mistake. Below is the code for generating Gaussain Window:</p>
  
  <pre><code>function y = Gaussain ( window, mu, sigma) 
  % y = exp (-((window - mu).^2)/(2*sigma^2)).* (1/(sigma * sqrt(2* pi)))  ;
  y = exp (-((window - mu).^2)/(2*sigma^2)) ;
  end
  </code></pre>
  
  <p>I am looking for a solution which does not use any Matlab toolkit's method. After fixing few things, I am getting this output:<img src="https://i.stack.imgur.com/VkEW6.png" alt="enter image description here"></p>