title: How to fit a curve on a discrete sequence data (stem) in Matlab?
body: <p>I have two matrices<code>FDX</code> and <code>TDX</code> (two classes) with <code>dim: 2xn</code>, that <code>FDX(1, :)</code>, <code>FDX(2, :)</code> are the number of objects and mean of them, respectively (also for <code>TDX</code>). I plot the above discrete sequence data using <code>stem</code> and now I want to show a curve instead of its lines to create a density map from points (like a pdf) or (like fit a curve to a Histogram), to better comparing between two classes.</p>
  
  <p>Is there any way to fit a curve on the following plot of <code>stem</code> in Matlab? </p>
  
  <p>I have also seen some links like <a href="https://stackoverflow.com/questions/15274205/histogram-from-two-vectors-in-matlab/">link1</a> and also <a href="https://stackoverflow.com/questions/18433455/fit-arbitrary-curve-to-data-points-in-matlab/">link2</a> but they are about histogram or continues data. Also, I have used the <code>fit</code> curve (<a href="https://www.mathworks.com/help/curvefit/fit.html/" rel="nofollow noreferrer">link</a> instead of the stem but two created curves are confusing. </p>
  
  <p>Example:</p>
  
  <pre><code>FDX = [9,12,7,7,8,4,10,8,5,9,10; 0.626023067402372,0.647560923068733,0.266314729708634,0.512920709657816,0.408389652529404,0.444588941849425,0.800367166464757,1.28429713933315,0.391101796334982,0.219880153736852,0.439931802866314];
  TDX = [1,1,2,1,1,1,1,1,1,1,1; 0.0888514059469934,0.0730468099283854,0.246560340244561,0.300711548987410,0.0871198693779434,3.11190476190476,0.185185185185183,0.246964650258985,0.113415750915749,0.132034632034618,0.201388888888900];
  
  
  f1 = fit(TDX(2, :)', TDX(1, :)','smoothingspline');
  plot(f1,'b', TDX(2, :)', TDX(1, :)','oc');
  hold on
  % stem(TDX(2, :), TDX(1, :),'*c');
  grid on   
  hold on
  
  
  f2 = fit(FDX(2, :)', FDX(1, :)','smoothingspline');
  plot(f2,'r',FDX(2, :)', FDX(1, :)','om');
  hold on
  % stem(FDX(2, :), FDX(1, :),'*m');
  grid on   
  hold off
  
  title('Displacement Curve X', 'Units', 'normalized', 'Position', [2.5, 1.1, 0]); 
  xlabel('Mean')
  ylabel('Number of Objs')
  legend('MeanTDX','MeanFDX')
  set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
  </code></pre>
  
  <p>In the following, there are two plots of <code>FDX</code> and <code>TDX</code> with dimensions of <code>2x432</code> and <code>2x114</code>, respectively.
  and</p>
  
  <p>Output of stem:</p>
  
  <p><a href="https://i.stack.imgur.com/cXr9R.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cXr9R.jpg" alt="enter image description here"></a></p>
  
  <p>Output of fit:</p>
  
  <p><a href="https://i.stack.imgur.com/9i6VU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9i6VU.jpg" alt="enter image description here"></a></p>
  
  <p>A model that I want:</p>
  
  <p><a href="https://i.stack.imgur.com/9HMb4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9HMb4.jpg" alt="enter image description here"></a></p>