Borrar filtros
Borrar filtros

How to omit repeated element in matrix

2 visualizaciones (últimos 30 días)
NA
NA el 3 de Oct. de 2018
Respondida: Steven Lord el 3 de Oct. de 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 comentarios
Akira Agata
Akira Agata el 3 de Oct. de 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 el 3 de Oct. de 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.

Iniciar sesión para comentar.

Respuestas (3)

ANKUR KUMAR
ANKUR KUMAR el 3 de Oct. de 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 comentario
ANKUR KUMAR
ANKUR KUMAR el 3 de Oct. de 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.

Iniciar sesión para comentar.


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

Iniciar sesión para comentar.


Steven Lord
Steven Lord el 3 de Oct. de 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 ___."

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by