For example: A = [1,2,3,4;5,6,7,8;9,10,11,12]; B=[2,1,4]. Each element in B means the desired element index of each row in A. That's to say, I want to get the 2nd element of A(1,:), 1st element of A(2,:), 4th element of A(3,:). How can I get this result with an efficient slicing method instead of a time-consuming for loop? Thanks.
MATLAB: How to slice 2d matrix based on a vector of indices of each row
accessMATLABslicing
Related Question
- Acquiring related Matrix Members
- From a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4]
- How to get the values from some of the coordinates
- Cumnwise multiplication between a matrix and a vector.
- Matrix indexing without loop
- How to multiply a vector 3 times to get a 3 dimentional matrix
- Indexing back into an array the same size as one that was just sorted
Best Answer