Find common elements of two array with repetition????

For example
A = [1234567]
B = [2348907]
now i hv to compare above two and want to store index of common elements.

답변 (1개)

Stephen23
Stephen23 2018년 9월 11일
편집: Stephen23 2018년 9월 11일
[C,ia,ib] = intersect(A,B)
For example:
>> A = [1,2,3,4,5,6,7];
>> B = [2,3,4,8,9,0,7];
>> [C,ia,ib] = intersect(A,B)
C =
2 3 4 7
ia =
2 3 4 7
ib =
1 2 3 7

댓글 수: 4

div
div 2018년 9월 11일
Thank you for your replay sir but i want A=[1,2,3,4,5,1,9] B=[1,4,3,7,5,1,9] so answer should be 1,3,5,1,9 .....i want those element which are common in same position in A and B with their index . And intersect give common elements with no repetition. Please help me out sir
Stephen23
Stephen23 2018년 9월 11일
편집: Stephen23 2018년 9월 11일
@div: well, that is a different question. Try this:
>> A = [1,2,3,4,5,1,9];
>> B = [1,4,3,7,5,1,9];
>> C = A(A==B)
C =
1 3 5 1 9
>> X = find(A==B) % (but logical indices are usually more efficient)
X =
1 3 5 6 7
div
div 2018년 9월 11일
not working sir . Please help this out.
It DOES work. I just copied and pasted and it worked fine. Post the code that you subsequently altered so we can see how your alterations ruined it.

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

div
2018년 9월 11일

댓글:

2018년 9월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by