How to omit repeated element in matrix

1 回表示 (過去 30 日間)
NA
NA 2018 年 10 月 3 日
回答済み: Steven Lord 2018 年 10 月 3 日
I have a E and x1 matrix
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13;
7 8;7 9;9 10;9 14;10 11;12 13;13 14]
x1=[1 2;1 5;2 5]
I want to write a code that if 1 is only connected to 2 and 5 and it used in X1, 1 should be omit from E.
  3 件のコメント
Akira Agata
Akira Agata 2018 年 10 月 3 日
Question for clarification.
Looking at the Graph E, x1=[1 2;1 5;2 5] is a sub-graph of E, as shown in the following figure. You want to remove this sub-graph x1 from E, or you want to remove only node 1 ?
Guillaume
Guillaume 2018 年 10 月 3 日
You really need to be clearer about what you want. Be more descriptive, use more words, go into the details. And use correct terms. Initially, you didn't even say that E represented the edges of a graph.
Let's assume you have a graph defined by the code:
E =[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13;7 8;7 9;9 10;9 14;10 11;12 13;13 14];
g = graph(E(:, 1), E(:, 2));
hplot = plot(g);
You also have x1:
x1 = [1 2; 1 5; 2 5]; %not sure how this is constructed
highlight(hplot, x1(:, 1), x1(:, 2))
You can find the degree of each node with
degree(g)
After that, I still have no idea what you want to do.

サインインしてコメントする。

回答 (3 件)

ANKUR KUMAR
ANKUR KUMAR 2018 年 10 月 3 日
Hope it helps.
E=[1 2;1 5;2 3;2 4;2 5;3 4;4 5;4 7;4 9;5 6;6 11;6 12;6 13; 7 8;7 9;9 10;9 14;10 11;12 13;13 14]
aa=unique(E(:,1));
id=find(arrayfun(@(x) length(find(E(:,1)==x)),unique(E(:,1)))==1);
E(ismember(E(:,1),id),:)
  1 件のコメント
ANKUR KUMAR
ANKUR KUMAR 2018 年 10 月 3 日
What's your expected output?
These are the pairs of numbers which are connected to only one. This means that, 3 is ONLY connected to 4, 5 is ONLY connected to 6 and so on.
If you are not satisfied with answer, please provide the answer which you are expecting.

サインインしてコメントする。


KSSV
KSSV 2018 年 10 月 3 日
To remove rows starting with 1 from E use:
E(E(:,1)==1,:) = []
  1 件のコメント
Guillaume
Guillaume 2018 年 10 月 3 日
What does is connected mean? That's not a mathematical term.

サインインしてコメントする。


Steven Lord
Steven Lord 2018 年 10 月 3 日
From your description if I had to guess I'd guess you wanted to remove all the cycles in your graph, leaving just a tree behind. If so, build a graph or digraph object and use the minspantree, shortestpathtree, or another function on this documentation page (maybe condensation or bctree?) on that graph or digraph.
If that's not what you want to do, start at the beginning. Explain at a higher level (no numbers or code) what you're trying to do and it may help us better understand your goal so we can offer more targeted suggestions. Fill in the blanks in this statement:
"I have a graph that contains cycles. I want to identify nodes that ___ and remove them or edges that ___ and remove them. When this is finished, I want my graph to have the property that ___."

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by