title: Optimizing extraction of data from a MATLAB matrix?
body: <p>Given an n-dimensional matrix of values: what is the most efficient way of retrieving values by arbitrary indices (i.e. coordinates)?</p>
  
  <p>E.g. in a random 5x5 matrix, if I want the values at (1,1) (2,3) and (4,5) what is the most efficient way of returning just the values at these coordinates?</p>
  
  <p>If I provide these coordinates in a separate matrix for example is there a one line of <a href="http://en.wikipedia.org/wiki/MATLAB" rel="nofollow noreferrer">MATLAB</a> which can do the job? Something like:</p>
  
  <pre><code>    x=rand(5,5);
  
      y=[[1,1];[2,3];[4,5]];
  
      z=x(y);
  </code></pre>
  
  <p>Except that doesn't work.</p>
  
  <p>One caveat however, for various reasons I am unable to use linear indexing - the results must be returned using the original indices. And the size of these matrices is potentially very large so I don't want to use loops either.</p>