title: How to Use fullfile in Matlab?
body: <p>I am studying Suever's <a href="https://stackoverflow.com/a/35891081/54964">answer</a> where I do not understand its application with <code>fullfile</code> in Code 1. </p>
  
  <p>Code 1 </p>
  
  <pre><code>filename=strcat('/Users/masi/Images/', 'p.1');
  save(fullfile(filename,'.mat'),'time');
  saveas(her, fullfile(filename,'.png'));
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>Error using save
  Cannot create '.mat' because '/Users/masi/Images/p.1' does not
  exist.
  </code></pre>
  
  <p>Code 2 </p>
  
  <pre><code>filename=strcat('/Users/masi/Images/', 'p.1');
  save(strcat(filename,'.mat'),'time');
  saveas(her, strcat(filename,'.png'));
  </code></pre>
  
  <p>Success! </p>
  
  <h2>Change made based on Daniel's <a href="https://stackoverflow.com/a/35892907/54964">answer</a></h2>
  
  <pre><code>filenameMat=fullfile('/Users/masi/Images/', 'p.1', '.mat');
  save(filenameMat,'time'); 
  </code></pre>
  
  <p>but still getting</p>
  
  <pre><code>Error using save
  Cannot create '.mat' because '/Users/masi/Images/p.1.mat' does not
  exist.
  </code></pre>
  
  <p>I do not understand. </p>
  
  <hr>
  
  <p>Why is code 1 giving the error?</p>