title: What is the best approach for setting startup variables in Matlab that are unaffected by commands such as `clear`?
body: <p>I have a situation in which a large amount of data output from Matlab programs needs to be stored in a specific location that can vary from machine to machine.  What I'd like to have is a global variable that is set at startup for each machine.  This variable could then be used by the various programs in order to determine the directory to store the output.  <strong>Note</strong> the approach will need to be <em>platform independent</em> as there a potentially 3 operating systems that will run these scripts.</p>
  
  <p><strong>One</strong> approach I considered is using <code>setenv</code>:</p>
  
  <pre><code>setenv('DATDIR',fullfile(path,to,dir));
  </code></pre>
  
  <p>Then the script/function could query this variable using:</p>
  
  <pre><code>savedir = getenv('DATDIR');
  </code></pre>
  
  <p>In this case the variable is unaffected by <code>clear</code> inside the Matlab environment. </p>
  
  <p><strong>Another</strong> approach I thought to use is simply creating a function (like <code>matlabroot</code>), which is on the path and simply returns a string to which the data directory path is assigned.</p>
  
  <pre><code>function path = datroot()
      path = fullfile(path,to,dir);
  end
  </code></pre>
  
  <p><strong>Finally, to my question:</strong> Is there another way to achieve the same result? If Matlab has it's own environment variables, I'd rather use those instead of functions or system-level variables.  Is this possible?</p>