I am using Matlab R2014a.
I have a 3-dimensional M x N x M matrix A. I would like a vectorized way to extract a 2 dimensional matrix B from it, such that for each i,j I
Try using sub2ind. This assumes g is defined as an MxN matrix with possible values 1, ..., M:
g
M
N
1
[ii, jj] = ndgrid(1:M, 1:N); B = A(sub2ind([M N M], ii, jj, g));