comparing 2 vectors for duplicates

1 次查看(过去 30 天)
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 中查找有关 Cell Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by