Info

此问题已关闭。 请重新打开它进行编辑或回答。

Logical indexing 2d to 3d without a for loop

1 次查看(过去 30 天)
Tyler
Tyler 2016-4-26
关闭: MATLAB Answer Bot 2021-8-20
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 个)

此问题已关闭。

Community Treasure Hunt

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

Start Hunting!

Translated by