Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Logical indexing 2d to 3d without a for loop
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (0 件)
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!