How can find column wise similarity of two matrix?

조회 수: 9 (최근 30일)
SM
SM 2021년 8월 5일
편집: Chunru 2021년 8월 6일
I have two matrice such as
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
If we look at these two matrices column wise, it is same at index 2 and 7. How can i find the index array [2 7] ?
Thanks!

답변 (2개)

Chunru
Chunru 2021년 8월 5일
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
find(all(A-B==0))
ans = 1×2
2 7
  댓글 수: 2
darova
darova 2021년 8월 5일
There is a problem
A = [1 2];
B = [1 2];
Chunru
Chunru 2021년 8월 6일
편집: Chunru 2021년 8월 6일
A = [1 2];
B = [1 2];
find(all(A==B, 1)) % explicitly 1st dimension (column wise)
ans = 1×2
1 2
A=[3 1 1 2 1 3 3 2
1 1 2 1 3 2 3 2 ];
B=[ 2 1 3 3 1 2 3 1
1 1 1 2 2 2 3 3 ];
find(all(A==B, 1)) % work for this too
ans = 1×2
2 7

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


Awais Saeed
Awais Saeed 2021년 8월 5일
Just use
idx = find(all(A == B))
idx =
2 7

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by