Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Logical indexing 2d to 3d without a for loop

1 vue (au cours des 30 derniers jours)
Tyler
Tyler le 26 Avr 2016
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi, this may be a simple question, but any help would be appreciated.
I have an array g = 100 x 5, and a much larger array w = 10000 x 10. I would like to have a 3D array, k = 100 x 10 x 5, where the first page (:,:,1) is the first column of g(:,1) indexing each column of w(:,:). Then my second page (:,:,2) is the second column of g(:,2) indexing each column of w, etc. If possible I would like to avoid a for loop, as I would like to increase the third dimension of k from 5 to 100 or 1000, but for now I would like to make sure I can do it. If a for loop is the only option I have, then that is fine. So far I have tried this:
for i = 1:5
k(:,:,i) = w(g(:,i),:);
end
Does this work? Or is there a better way to do this?
Thank you for the help!

Réponses (0)

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by