3d matrix: how to use (row, column) pairs with 3rd dimension wildcard in MATLAB?
I have a 3 dimensional matrix, and a list of (row, column) pairs. I would like to extract the 2 dimensional matrix that corresponds to the elements in those positions, projected through the depth of the matrix. For instance, suppose, >> a = rand(4, 3, 2) a(:,:,1) = 0.5234 0.7057 0.0282 0.6173 0.2980 0.9041 0.7337 0.9380 0.9639 0.0591 0.8765 0.1693 a(:,:,2) = 0.8803 0.2094 0.5841 0.7151 0.9174 0.6203 0.7914 0.7674 0.6194 0.2009 0.2542 0.3600 >> rows = [1 4 2 1]; >> cols = [1 2 1 3]; What I'd like to get is, 0.5234 0.8765 0.6173 0.0282 0.8803 0.2542 0.7151 0.5841 maybe with some permutation of