Comparing two arrays of different length

Hi,
I have two arrays like, A=[11 11 2 3; 5 2 6 9] and B=[11 3; 2 9]. I want to know the indices of array A where the column of B is equal to column of A. In this case, the indices are [2 4].
How can I do that?
Thanks in Advance.

 채택된 답변

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014년 11월 17일

3 개 추천

You could this to find it:
idx = ismember(A', B', 'rows');
c = 1:size(A, 2);
d = c(idx); % is your answer

댓글 수: 2

Majbah
Majbah 2014년 11월 17일
Thanks!
indeed, maybe
ismember(0, unique(idx))
used with 0 (no-coincident) or 1 (coincident), may be useful.
Then combined with
length(unique(idx))
For to know about the totallity of coincidences

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 11월 17일

4 개 추천

A=[11 11 2 3; 5 2 6 9]
B=[11 3; 2 9]
idx=find(ismember(A',B','rows'))

카테고리

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

태그

질문:

2014년 11월 17일

댓글:

2021년 10월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by