2d matrix of index to get value of 3D matrix
3 views (last 30 days)
Show older comments
Hello,
I have matrix A with size (37,30,1000); and a matrix B with size (37,1000). I want to use matrix B as a matrix of indexes to get value from A.
The index refers to which column in 3D matrix I want to get the value for each 1st and 3rd dimension.
Is there anyone having an idea how to solve it (prefer not using loop).
Thank you,
Answers (2)
Bruno Luong
on 24 Oct 2018
Edited: Bruno Luong
on 24 Oct 2018
I'm pretty sure I answered something along this line few days ago
[m,n,p] = size(A);
[I,K] = ndgrid(1:m,1:p);
EXTRACT = A(sub2ind(size(A),I,B,K))
2 Comments
Bruno Luong
on 24 Oct 2018
Edited: Bruno Luong
on 24 Oct 2018
Type
min(B(:))
max(B(:))
and verify they are with [1,n] interval, (n=30) in your case.
See Also
Categories
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!