Azzera filtri
Azzera filtri

How to omit repeated element in matrix

2 visualizzazioni (ultimi 30 giorni)
NA
NA il 3 Ott 2018
Risposto: Steven Lord il 3 Ott 2018
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 Commenti
Akira Agata
Akira Agata il 3 Ott 2018
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 il 3 Ott 2018
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.

Accedi per commentare.

Risposte (3)

ANKUR KUMAR
ANKUR KUMAR il 3 Ott 2018
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 Commento
ANKUR KUMAR
ANKUR KUMAR il 3 Ott 2018
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.

Accedi per commentare.


KSSV
KSSV il 3 Ott 2018
To remove rows starting with 1 from E use:
E(E(:,1)==1,:) = []
  1 Commento
Guillaume
Guillaume il 3 Ott 2018
What does is connected mean? That's not a mathematical term.

Accedi per commentare.


Steven Lord
Steven Lord il 3 Ott 2018
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 ___."

Categorie

Scopri di più su Graph and Network Algorithms in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by