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!