Eliminating common elements across multiple arrays

i have data like-
A1 x A2 y
1 1.2 1 1.3
3 1.3 2 1.6
4 1.4 3 1.5
5 1.5 4 1.4
8 1.4 6 1.4
9 1.7 7 1.7
11 1.6 8 1.5
12 1.3 9 1.7
14 1.6 10 1.2
15 1.8 12 1.3
13 1.2
14 1.5
15 1.9
and i want the output in which both are common like-
A x y
1 1.2 1.3
3 1.3 1.5
4 1.4 1.4
8 1.4 1.5
9 1.7 1.7
12 1.3 1.3
14 1.6 1.5
15 1.8 1.9

回答 (1 件)

Stephen23
Stephen23 2016 年 12 月 5 日
編集済み: Stephen23 2016 年 12 月 5 日

0 投票

This is easy using intersect and some basic MATLAB indexing:
Ax = [1;3;4;5;8;9;11;12;14;15];
x = [1.2;1.3;1.4;1.5;1.4;1.7;1.6;1.3;1.6;1.8];
Ay = [;1;2;3;4;6;7;8;9;10;12;13;14;15];
y = [1.3;1.6;1.5;1.4;1.4;1.7;1.5;1.7;1.2;1.3;1.2;1.5;1.9];
[A,idx,idy] = intersect(Ax,Ay);
xn = x(idx);
yn = y(idy);
which gives:
>> [A,xn,yn]
ans =
1 1.2000 1.3000
3 1.3000 1.5000
4 1.4000 1.4000
8 1.4000 1.5000
9 1.7000 1.7000
12 1.3000 1.3000
14 1.6000 1.5000
15 1.8000 1.9000

2 件のコメント

AKHILESH KUMAR
AKHILESH KUMAR 2016 年 12 月 6 日
Tanks, It work very well.
Stephen23
Stephen23 2016 年 12 月 7 日
@AKHILESH KUMAR: I am glad that it worked. Please accept my answer if it helped you.

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

タグ

タグが未入力です。

質問済み:

2016 年 12 月 5 日

コメント済み:

2016 年 12 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by