title: Matrix operations matlab to move values around
body: <p>I have a matrix that I'd like to create a new ordering of, for example,</p>
  
  <pre><code>vals = [1 2; 3 4]
  </code></pre>
  
  <p>I also have two matrices, new_x and new_y such that <code>new_x(a,b) = j</code> and <code>new_x(a,b) = k</code> means that I want the value at vals (a,b) to be mapped to new_vals(j,k).</p>
  
  <p>For example, given</p>
  
  <pre><code>new_x = [1 2; 2 1]
  new_y = [2 2; 1 1]
  </code></pre>
  
  <p>I'd want 
      new_vals = [4 3; 1 2]</p>
  
  <p>I understand that I could just write two for loops to build the new array, but matlab is notoriously good at providing operations on entire matricies.  My question is, how would I build new_vals without the for loops?</p>