title: Access a list of entries in MATLAB
body: <p>I have a huge matrix <code>MxN</code> matrix, say, <code>A=rand([M,N]);</code> and an index vector with <code>N</code> integer values between <code>1</code> and <code>M</code>, say, <code>RandomIndex = randi(M,[1,N]);</code>.</p>
  
  <p>Now I would like to generate a row vector with entries </p>
  
  <pre><code>result = [A(RandomIndex(1),1), A(RandomIndex(2),2), ..., A(RandomIndex(N),N)]
  </code></pre>
  
  <p>What would be an efficient way to do this? It should be a very cheap operation but all my implementations are slow. I don't think there is a notation in Matlab to do this directly, is there?</p>
  
  <p>The fastest option so far is </p>
  
  <pre><code>indexFunction = @(r,c) A(r,c);
  result = cell2mat(arrayfun(indexFunction,RandomIndex,1:N,'UniformOutput',false));
  </code></pre>
  
  <p>Is there a more efficient way?</p>