2d matrix of index to get value of 3D matrix
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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,
Respuestas (2)
Bruno Luong
el 24 de Oct. de 2018
Editada: Bruno Luong
el 24 de Oct. de 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 comentarios
Bruno Luong
el 24 de Oct. de 2018
Editada: Bruno Luong
el 24 de Oct. de 2018
Type
min(B(:))
max(B(:))
and verify they are with [1,n] interval, (n=30) in your case.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!