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!