title: Use an array item as replacement in a MATLAB regexpr
body: <p>I have a string containing a math function like this:</p>
  
  <pre><code>sin(x[1]) + cos(x[2]) + tan(x[3]) + x[1]
  </code></pre>
  
  <p>Now I want to replace each x[number] with a letter of the alphabet using regexpr. The result should look like this:</p>
  
  <pre><code>sin(a) + cos(b) + tan(c) + a
  </code></pre>
  
  <p>So I defined an alphabet array like this:</p>
  
  <pre><code>alphabet = ('a':'z')
  </code></pre>
  
  <p>This is my first regexpr that just replaces every x[number] with an 'a':</p>
  
  <pre><code>regexprep(functionString,'x\[(\d+)\]','${alphabet(1)}');
  </code></pre>
  
  <p>What I tried to make it replace with the right letter, is using $1 instead of 1. I thought this would not use alphabet(1) but dynamically the item at the right alphabet index.</p>
  
  <pre><code>regexprep(functionString,'x\[(\d+)\]','${alphabet($1)}');
  </code></pre>
  
  <p>Instead I am getting an error that the index exceeds the matrix dimensions.</p>
  
  <p>Does anybody know what I am doing wrong? How do I get the right letter?
  Thanks in advance!</p>