# Need to remove elements which repeated 2 times

2 views (last 30 days)
Na on 3 Mar 2020
Commented: Na on 3 Mar 2020
I have
A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6];
element 2, 4, 6 repeated 2 times. I want to remove them from A.
A_new=[1,3; 1,5]

Na on 3 Mar 2020
Yes, I want to remove rows if either element repeated only twice. 3 repeated three times.
A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6];
N=max(max(A));
for i=1:N
if sum(sum(A==i),2)==2
A(any(ismember(A,i),2),:)=[];
end
end
This code removes all element in A.
but I want to have A_new=[1,3; 1,5]
Turlough Hughes on 3 Mar 2020
If you have values repeated in the same row and nowhere else, is that row to be deleted also?
i.e. for this input
A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6; 8 8];
A_new = [1 3; 1 5; 8 8]; %or
A_new = [1 3; 1 5];
Na on 3 Mar 2020
in my case should be A_new = [1 3; 1 5];

Alex Mcaulley on 3 Mar 2020
A=[1 2; 1,3; 1,4; 1,5; 2,3; 3,6; 4,5; 5,6];
N=max(max(A));
A_new = A;
for i=1:N
if sum(sum(A==i),2)==2
A_new(any(ismember(A_new,i),2),:)=[];
end
end