Remove same element from vector
조회 수: 12 (최근 30일)
이전 댓글 표시
I have this vector
E=[1,2;1,3;1,6;2,3;2,4;3,7;4,5;5,6;5,7;6,7;1,2;2,4;6,8];
I want to omit same element and also (6,8).
As 8 is not conneted to other points, I want to omit it too.
result is: E=[1,2;1,3;1,6;2,3;2,4;3,7;4,5;5,6;5,7;6,7];
댓글 수: 0
채택된 답변
Andrei Bobrov
2018년 11월 30일
a = sort(unique(E,'rows'),2);
b = unique(a(:));
c = hist(a(:),b);
out = a(all(ismember(a,b(c > 1)),2),:);
댓글 수: 0
추가 답변 (2개)
madhan ravi
2018년 11월 30일
편집: madhan ravi
2018년 11월 30일
E=[1,2;1,3;1,6;2,3;2,4;3,7;4,5;5,6;5,7;6,7;1,2;2,4;6,8];
[E,~,~]=unique(E,'rows');
idx=ismember(E,[6 8],'rows');
E=E(~idx,:) %expected result
command window:
>> E
E =
1 2
1 3
1 6
2 3
2 4
3 7
4 5
5 6
5 7
6 7
>>
Guillaume
2018년 11월 30일
What you have completely failed to mention in your question and left for us to guess is that your E matrix represents the edges of a graph. Without that information, "8 is not connected to other point" is meaningless.
One way to do what you want:
E=[1,2;1,3;1,6;2,3;2,4;3,7;4,5;5,6;5,7;6,7;1,2;2,4;6,8];
g = graph(E(:, 1), E(:, 2)); %remove duplicate edges and make graph
g = simplify(g); %remove duplicate edges and self loops
g = rmnode(g, find(degree(g) <= 1)); %remove isolated nodes or nodes with only one edge
E = g.Edges.EndNodes
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!