필터 지우기
필터 지우기

comparing 2 vectors for duplicates

조회 수: 1 (최근 30일)
Sam
Sam 2016년 3월 17일
편집: Adam 2016년 3월 17일
Hello,
I have a vector of 465051 x 1 elements, and a vector of 1197 x 1 elements. The 465051 vector contains all the 1197 elements, but I don't know where. So I created the following code:
[num,txt,raw] = xlsread('cg_uit_beta2'); %extracting the 465051 vector
A = txt(:,1); %extracting the 465051 vector
[num2,txt2,raw2] = xlsread('cg_uit_beta2_2'); %extracting the 1197 vector
B = txt2(:,1); %extracting the 1197 vector
L = ismember(A,B); %find rownumber of duplicates in the 465051 vector
I = find(L); %find rownumber of duplicates in the 465051 vector
So, now I know where the 1197 duplicates in the 465051 vector are. But now I just need to extract these values out of the 465051 vector... but how do I do that?
Thanks!

채택된 답변

Adam
Adam 2016년 3월 17일
편집: Adam 2016년 3월 17일
[L,I] = ismember(A,B);
vals = A(I~=0);
should work. The extra 'find' step is un-necessary if you use the second output of ismember. If you prefer though:
L = ismember(A,B);
I = find(L);
vals = A(I);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by