I have an n x m x 3 matrix A and an n x m matrix B. B contains the values 1, 2, or 3, referring to the three different layers in A. I want to create another n x m matrix C where each point is the value of A from the layer specified by B. For instance, if A(1,1,:) = [8 6 5], B(1,1) = 2, then C(1,1) = 6, because B at that point specifies taking from the second layer. I know how to do this with a loop, but I was wondering if there was an easier, vectorized way to do so. Thanks!
MATLAB: How to create 2D matrix from 3D without a loop
3d matrixmaskmatrixno loopvectorize
Related Question
- How to populate 2d-array from 3d array with page indices
- Exponentiation of Matrix Columns by different Powers
- How to change this matrix in this manner
- Fast matrix multiplication in loop
- Get all sets of cells from two arrays of cells, each of which contains exactly one cell from each column of each arrays.
- Efficient Code for Filling Rows of an Array involving Indices Ranges
Best Answer