フィルターのクリア

how to find the same elements from 2 vectors

14 ビュー (過去 30 日間)
Ahmed Alnahdi
Ahmed Alnahdi 2015 年 4 月 27 日
コメント済み: Ahmed Alnahdi 2015 年 4 月 27 日
Hi,
I have a question about intersections(same) between two victors. for example if I have vector_1=[1,2,3,4,5], Vector_2=[6,5,7,1,8] I want to be able to find the repeated elements from both vectors , in this case 1 and 5. And is it possible to put a minimum threshold or limit for what number to look for ie. above 2
Thanks in advance .....

採用された回答

pfb
pfb 2015 年 4 月 27 日
編集済み: pfb 2015 年 4 月 27 日
% this is going to find the common elements (1 and 5)
I=intersect(vector_1,vector_2);
% this is going to introduce the threshold (only 5 survives)
I=I(I>2);
  3 件のコメント
pfb
pfb 2015 年 4 月 27 日
It's all explained in the documentation for intersect
[I,i1,i2] = intersect(vector_1,vector_2);
will give you the indices of the common elements in vector_1 and vector_2. That is, the common elements stored in I correspond to
vector_1(i1)
and
vector_2(i2)
If you want to enforce the threshold, then it is probably convenient to define
t = I>2;
and then
I=I(t);
i1=i1(t);
i2=i2(t);
Ahmed Alnahdi
Ahmed Alnahdi 2015 年 4 月 27 日
It perfectly did its job, thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by