Select values of a matrix given a matrix of indices?
1 view (last 30 days)
Show older comments
MementoMori on 26 Mar 2023
Hi, suppose we have a matrix
Now I have two matrices:
Now I want to create a new matrix
is there any fast way to do this?
Stephen23 on 26 Mar 2023
Edited: Stephen23 on 26 Mar 2023
"is there any fast way to do this?"
A = rand(10,10)
x = [2,3;5,7];
y = [4,6;1,2];
idx = sub2ind(size(A),x,y);
B = A(idx)
More Answers (0)
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!