필터 지우기
필터 지우기

3D matrix pattern matching

조회 수: 4 (최근 30일)
Shilpi Mishra
Shilpi Mishra 2021년 5월 19일
편집: Jonas 2021년 5월 20일
Find which row of 3d matrix matches an array along the third dimension. For ex:
I want to find [1 0 0] along 3rd dimension of Zb, so here Zb(4,1,:) , Zb(5,4,:) and some others match [1, 0, 0]. How to know if the match occurs (for any random value of 3rd dimension of matrix) and if so, what are the row, column indices? Also, can this be done without for loop?

채택된 답변

Jonas
Jonas 2021년 5월 19일
you can use e.g.
a(:,:,1)=ones(2);
a(:,:,2)=2*ones(2);
a(:,:,3)=[1 3; 3 1];
pattern(1,1,:)=1:3;
whereToFind=all(a==pattern,3)
  댓글 수: 2
Shilpi Mishra
Shilpi Mishra 2021년 5월 20일
Thanks a lot, to know positions of 1 in the whereToFind, is there a direct way without loop to get list of indices as [4,1], [3,2] and so on?
Jonas
Jonas 2021년 5월 20일
편집: Jonas 2021년 5월 20일
yes, use
[row,col]= find(whereToFind)
if you want the pairwise indices then [row col] will give you all pairs

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by