フィルターのクリア

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 Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by