Eliminating common elements across multiple arrays

2 次查看(过去 30 天)
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
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

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by