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

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,

Risposte (1)

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 Commento

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.

Accedi per commentare.

Richiesto:

il 24 Ott 2018

Commentato:

il 24 Ott 2018

Community Treasure Hunt

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

Start Hunting!

Translated by