How can I keep the rows where the elements of 1st column are in 2nd column
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I have a edge list as below:
1 2
1 3
1 9
2 1
2 3
3 1
3 2
3 4
3 9
I need in matlab rows where 1st column values are present in 2nd column. i.e. From the above I need rows in which 1st column values(1,2,3) are present in 2nd column(i.e. keep the rows where 2nd column too has values 1,2,3 and the rest remove. So finally it should be:
1 2
1 3
2 1
2 3
3 1
3 2
Réponses (1)
Sean de Wolski
le 1 Juil 2014
M=[1 2
1 3
1 9
2 1
2 3
3 1
3 2
3 4
3 9];
Mpc = M(ismember(M(:,2),unique(M(:,1))),:)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!