Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to find all different turns in a graph from Adjacency List?

Subject: How to find all different turns in a graph from Adjacency List?

From: Jack

Date: 15 Jul, 2010 23:53:04

Message: 1 of 3

Hi;
I have the following representation of a graph in a form of Adjacenct List:
0 1 2 19 20 21
1 0 3 9 10
2 0 14
3 1 4 5 6
.
.
.
which means for the first row, the node 0 is connected to node 1 and node 2..etc
I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10).

Many thanks

Subject: How to find all different turns in a graph from Adjacency List?

From: Bruno Luong

Date: 16 Jul, 2010 06:41:06

Message: 2 of 3

"Jack " <jack_sama_1981@yahoo.com> wrote in message <i1o710$mlh$1@fred.mathworks.com>...
> Hi;
> I have the following representation of a graph in a form of Adjacenct List:
> 0 1 2 19 20 21
> 1 0 3 9 10
> 2 0 14
> 3 1 4 5 6
> .
> .
> .
> which means for the first row, the node 0 is connected to node 1 and node 2..etc
> I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10).
>

help NCHOOSEK

Bruno

Subject: How to find all different turns in a graph from Adjacency List?

From: Jack

Date: 16 Jul, 2010 17:10:22

Message: 3 of 3

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i1ouu2$m8j$1@fred.mathworks.com>...
> "Jack " <jack_sama_1981@yahoo.com> wrote in message <i1o710$mlh$1@fred.mathworks.com>...
> > Hi;
> > I have the following representation of a graph in a form of Adjacenct List:
> > 0 1 2 19 20 21
> > 1 0 3 9 10
> > 2 0 14
> > 3 1 4 5 6
> > .
> > .
> > .
> > which means for the first row, the node 0 is connected to node 1 and node 2..etc
> > I want to find all possible nodes in the graph and list them in an nx3 matrix. So for the first row the possible turns are [1 0 2; 1 0 19; 1 0 20; 1 0 21; 2 0 19; 2 0 20; 2 0 21;19 0 20; 19 0 21; 20 0 21] so the number of different turns for the first node will be (5 chose 2= 10).
> >
>
> help NCHOOSEK
>
> Bruno

thanks for the advice; I used the following code but is there a faster way?
S =

     0 1 2 3 4
     1 0 2 4 NaN
     2 0 1 3 NaN
     3 0 2 4 NaN
     4 0 1 3 NaN

a= size (S);
comb=[];
for i=1:a(1)
    A=S(i,:)
    A(1)=[];
    B= nchoosek (A,2);
    C=[];
    C(:,1)=B(:,1);
    C(:,2)=S(i,1);
    C(:,3)=B(:,2);
    comb=[comb;C]
end
D=[];
D=comb(:,1);
index=find(isnan(D))
comb(index,:)=[];
D=comb(:,3);
index=find(isnan(D));
comb(index,:)=[]

thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us