title: Initializing Variable Only Once in Matlab Recursive Function
body: <p>Is there any way to initialize a variable within a recursive Matlab function <strong>only</strong> the first time the function is called?</p>
  
  <p>The function calls itself multiple times within the function and I want to set a variable <code>d=0</code> at the very start of the function, and immediately after I want to set <code>d=d+1</code>.</p>
  
  <p>Every subsequent time the function is called I want <code>d=d+1</code>. I want to initialize the variable inside of the function, and also I don't want to pass it as a parameter of the function. </p>
  
  <p>I get the feeling I need to declare a global variable however I still can't figure out how to do so without changing it's value back to 1 every time the function is called. </p>