Thread Subject:
Extracting index for connections in network

Subject: Extracting index for connections in network

From: Ulrik Nash

Date: 8 May, 2012 14:04:07

Message: 1 of 2

Hi Everyone,

Suppose I have a square matrix which depicts nodes and edges on a graph, with 0's indicating no connection and 1's indicating connections between nodes. For example:

A = [1 0 1 1; 0 1 0 0; 1 0 1 1; 1 0 1 1]

What I wish to achieve is the creation of matrix B, which has two columns. The first column contains the row index of the 1's under the diagonal, and the second column contains the associated column index. For example, for A the result would be:

B = [3 1;4 1; 4 3]

Is there a of achieving this without looping through A?

Subject: Extracting index for connections in network

From: Matt J

Date: 8 May, 2012 14:30:07

Message: 2 of 2

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <job94n$ble$1@newscl01ah.mathworks.com>...
>
> What I wish to achieve is the creation of matrix B, which has two columns. The first column contains the row index of the 1's under the diagonal, and the second column contains the associated column index. For example, for A the result would be:
>
> B = [3 1;4 1; 4 3]
>
> Is there a of achieving this without looping through A?
=============

Here's one way, though I'm not sure a loops would be sub-optimal

[i,j]=find(tril(A,-1));
B=[i,j];

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
matrix Ulrik Nash 8 May, 2012 10:04:12
network Ulrik Nash 8 May, 2012 10:04:12
graph Ulrik Nash 8 May, 2012 10:04:12
nodes Ulrik Nash 8 May, 2012 10:04:12
edges Ulrik Nash 8 May, 2012 10:04:12
rssFeed for this Thread

Contact us