Eliminating common elements across multiple arrays

2 vues (au cours des 30 derniers jours)
AKHILESH KUMAR
AKHILESH KUMAR le 5 Déc 2016
Commenté : Stephen23 le 7 Déc 2016
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

Réponses (1)

Stephen23
Stephen23 le 5 Déc 2016
Modifié(e) : Stephen23 le 5 Déc 2016
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 commentaires
AKHILESH KUMAR
AKHILESH KUMAR le 6 Déc 2016
Tanks, It work very well.
Stephen23
Stephen23 le 7 Déc 2016
@AKHILESH KUMAR: I am glad that it worked. Please accept my answer if it helped you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by