How to access array element from vector of its entries

Is there a function that takes an array A and a vector [v1 ... vn] as inputs and returns A(v1,...,vn), provided A has `size' m1 x ... x mn, and 1 ≤ vi ≤ mi for all i between 1 and n?

 Accepted Answer

One way:
c = num2cell(v);
result = A(sub2ind(size(A),c{:}));

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!