Get corresponding value of a 3D matrix using an index vector

12 views (last 30 days)
Hello,I have a 3D matrix, dimesion 37*30*1000. And an index vector i, dimension 37*1, containing the index of the column I want to get the value for each row from 1--> 37
Could anyone tell me how to get the 37*1*1000 new matrix from the original matrix and the index vector?
Thank you,

Answers (1)

KSSV
KSSV on 24 Oct 2018
A = rand(37,30,100) ;
C = 3 ; % say you need third columns from each
iwant = zeros(37,1,100) ;
for i = 1:100
iwant(:,1,i) = A(:,C,i) ;
end
  1 Comment
heidi pham
heidi pham on 24 Oct 2018
Hello, thanks for your answer. but is there any other way not using loop, since one of my dimession is 100000 actually. I guess sub2ind should work, but I dont know how to adapt it in my case.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!