I have a 3d array A with nr rows, nc columns, and np pages, and an nr x nc indexing matrix I with integer elements between 1 and np. I want to create a matrix B with elements picked from A, where for each position (r,c) the element is picked from the page of A given by the value of I at that position.
A straightforward way to do this would be the double loop:
B = zeros(nr,nc);for r = 1:nr for c = 1:nc p = I(r,c); B(r,c) = A(r,c,p); endend
Is there a way to accelerate this by vectorization for large arrays?
Best Answer