How can I keep the rows where the elements of 1st column are in 2nd column
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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
Answers (1)
Sean de Wolski
on 1 Jul 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))),:)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!