Borrar filtros
Borrar filtros

Eliminating common elements across multiple arrays

3 visualizaciones (últimos 30 días)
AKHILESH KUMAR
AKHILESH KUMAR el 5 de Dic. de 2016
Comentada: Stephen23 el 7 de Dic. de 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

Respuestas (1)

Stephen23
Stephen23 el 5 de Dic. de 2016
Editada: Stephen23 el 5 de Dic. de 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 comentarios
AKHILESH KUMAR
AKHILESH KUMAR el 6 de Dic. de 2016
Tanks, It work very well.
Stephen23
Stephen23 el 7 de Dic. de 2016
@AKHILESH KUMAR: I am glad that it worked. Please accept my answer if it helped you.

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by