title: MATLAB: dynamic variable definitions
body: <p>For a numerical simulation in MATLAB I have parameters defined in an .m file.</p>
  <pre class="lang-lisp prettyprint-override"><code>%; Parameters as simple definitons
  amb.T = 273.15+25;           ... ambient temperature [K]
  amb.P = 101325;              ... ambient pressure [Pa]
  
  combustor.T = 273.15+800;    ... [K]
  combustor.P = 100000;        ... [Pa]
  combustor.lambda = 1.1;
  
  fuel.x.CH4 = 0.5;            ... [0..1]
  fuel.n = 1;
  
  air.x.O2 = 0.21;
  
  %; more complex definitions consisting of other params
  air.P = reactor.P;
  air.T = amb.T;
  air.n = fuel.x.CH4 * 2 * fuel.n * combustor.lambda / air.x.O2;
  </code></pre>
  <p>Consider this set as 'default' definitions. For running <strong>one</strong> simulation this definitions works fine.</p>
  <p>It's getting more complicated if I want to change one of these parameters programmatically for a parameter study (the effect of changing parameters on the results), that is, to perform <strong>multiple</strong> simulations by using a <code>for</code> loop. In the script performing this I want to change the defintion of several parameters beforehand, i.e. overwrite default definitions. <strong>Is there a way to do this without touching the default definitions in-code</strong> (comment them/overwrite them literally)? It should be possible to change any parameter in the study-performing script and catch up on default definitions from the listing above (or the other way round).</p>
  <p>Let me illustrate the problem with the following example: If I want to vary <code>combustor.lambda</code> (let's say running from <code>0.9</code> to <code>1.3</code>) field <code>air.n</code> has to be evaluated again for the change to take place in the actual simulation. So, I could evaluate the listing again, but this way I would lose the study-defined <code>combustor.lambda</code> for the default one.</p>
  <p>I am thinking about these solutions but I cannot get to how to do this:</p>
  <ul>
  <li>Use references/handles in a way that the struct fields only hold the definitions, not the actual values. This allows for changing default definitions before 'parsing' the whole struct to get the actual values.</li>
  <li>Evaluate the default definition set by a function considering (non-default) definitions defined preliminarily, i.e. skipping these lines of the default definition set during evaluation.</li>
  <li>Any OOP approach. Of course, it is not limited to <code>struct</code> data types, but on the other hand, maybe there are useful functions for <code>structs</code>?</li>
  </ul>
  <h3>Edit:</h3>
  <p>The purpose of the default set is for the programmer to be as free as possible in choosing the varying parameters with any of the other parameters keeping their default definition which can be independent (= values) as well as dependent (= <em>equations</em> like <code>air.n</code>).</p>