MATLAB: Indexing a chunk of a of a multidimensional array using a vector of indices

indexingMATLAB

I have a multidimensional array A that is say NxNxNxNxN. I want to access the NxN 2d array i,j,k,:,:, using the index vector p=[i,j,k]. What is the smart way to pull this out of A, such as A(p,:,:)? I would rather not use squeeze(A(p(1),p(2),p(3),:,:)).

Best Answer

You could call subsref directly, but I'm not sure it's that simpler:
subsref(A, struct('type', '(), 'subs', {[num2cell(p), {':', ':'}]}))