Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Logical indexing 2d to 3d without a for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!