Extracting indices from 3D matrix for another 3D matrix
3 ビュー (過去 30 日間)
古いコメントを表示
I have two 3D matrices A and B, of the same size and another 3d matrix I of the same size containing some indices corresponding to the first dimension of A. I want to do something like A(I)/B(I).
Specifically, A(I(x,y,z),y,z) divide it by B(I(x,y,z),y,z) for all of x,y,z. How do I do it quickly maybe using repmat or sub2ind or simply logical indexing?
If it is not clear I can post an example.
1 件のコメント
Jyotsna Talluri
2020 年 4 月 6 日
You can use logical indexing in order to access the values from the matrices,but there might be a possibility that the value of I(x,y,z) is greater than the number of rows of matrices A and B
回答 (1 件)
Matt J
2020 年 4 月 6 日
[m,n,p]=size(A);
[~,J,K]=ndgrid(1:m,1:n,1:p);
idx=sub2ind([m,n,p],I,J,K);
A(idx)./B(idx)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!