how to find index from matrix in another matrix?
2 ビュー (過去 30 日間)
古いコメントを表示
Hi all,
I have two different 3d matrices (A=72*46*2192) and (B=72*46*2192), in which I want to find the indices equal to 4 and 5 from A in B.
The result should be a 3d matrix as well, not linear indices.
Any help would be appreciated.
2 件のコメント
回答 (1 件)
Fangjun Jiang
2022 年 7 月 26 日
編集済み: Fangjun Jiang
2022 年 7 月 27 日
%C is the logical index matrix.
A=zeros(2,3,4);
A(:,:,4)=4;
A(:,3,4)=5;
C=or(A==4,A==5)
%To use it to select corresponding elements in B
B=rand(2,3,4);
B_select=B(C)
LinearIndex=find(C);
[SubX,SubY,SubZ]=ind2sub(size(C),LinearIndex)
2 件のコメント
Fangjun Jiang
2022 年 7 月 27 日
See the updated answer to understand
- Logical index
- Linear index
- Subscript index
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!