title: Getting the mapping for a permutation in MATLAB
body: <p>Say I have two arrays where one is a permutation of the other:</p>
  
  <pre><code>A = [2 1 5 3 7]
  B = [7 2 1 3 5]
  </code></pre>
  
  <p>with no repetitions in either array. </p>
  
  <p>How can I obtain the permutation mapping between both?</p>
  
  <p>E.g. <code>A-&gt;B</code> should be:</p>
  
  <pre><code>[2, 3, 5, 4, 1]
  </code></pre>
  
  <p>which means: </p>
  
  <pre><code>A(1) -&gt; B(2)
  A(2) -&gt; B(3)
  A(3) -&gt; B(5)
  A(4) -&gt; B(4)
  A(5) -&gt; B(1)
  </code></pre>
  
  <h2>Update:</h2>
  
  <p>Is there a <strong>fast</strong> vectorized solution that does not use <code>ismember</code> ? In my experience, <code>ismember</code> tends to be slow for very large arrays.</p>