Problem 45882. Matrix indexing with two vectors of indices (★★)
(copy of Prob 589)
Given a matrix M and two index vectors a and b, return a row vector x where x(i) = M(a(i),b(i)). Thus, if
a = [ 1 2 5 ]
b = [ 4 5 2 ]
M = [ 17 24 1 8 15;
23 5 7 14 16;
4 6 13 20 22;
10 12 19 21 3;
11 18 25 2 9 ]
then
x = [ M(1,4) M(2,5) M(5,2) ]
x = [ 8 16 18 ]
Avoid using for/while loops.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers39
Suggested Problems
-
17881 Solvers
-
Return a list sorted by number of occurrences
2753 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
10697 Solvers
-
609 Solvers
-
Flip the vector from right to left
8654 Solvers
More from this Author52
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!