Got Questions? Get Answers.
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:
Tracking Node Path in Graph

Subject: Tracking Node Path in Graph

From: Kelsey

Date: 10 Jun, 2011 19:00:20

Message: 1 of 1

I'm trying to develop several visualization of tools for a network of individuals (nodes). For example, one tool computes the (user input) number of smallest distances between each node and every other node, and then plots arrows between nodes that are sensing each other (they sense each other one is a shortest distance away from another). Some edges are directed because the sensing only travels in one direction, and some are undirected because the sensing goes both ways--each member of the pair connected is one of each other's nearest neighbors. Now, I'm trying to make a tool that finds independent groups nested inside the larger network. To do this, I want to traverse the array of node pairs (both directed and undirected), and track each "node path". So, say the first pair is 1 6. Then I want to find where 6 appears in the first column and use whatever is in the column next to it
as the connector. If what is in the second column is ever the first node that we started with, then there's a complete path, which means that those pair connections define an independent group within the larger network. I'm having trouble coding this because the code doesn't seem to be updating. Here's what I have so far:

for i=1:length(directedEdges)
    nodePath(j,:) = directedEdges(i,:);
    nodeConnection = nodePath(j,2);
    while nodeConnection ~= nodePath(i,1)
        [nodeSensor,nodeSensed] = find(directedEdges(:,1)==nodeConnection);
        nodePath(j,:) = directedEdges(nodeSensor,:);
        nodeConnection = nodePath(j,2);
^this is what I need help with. I don't know how to change the assignment statements so that the code properly checks every node path to see if it's an independent cycle.

   % if there's a complete cycle, plot it: this code works.
   if nodeConnection == nodePath(i,1)
        directedEdgesCycle = nodePath;
        for l=1:numberOfNeighbors
            for k=1:length(directedEdgesCycle)
                xVal1 = x(directedEdgesCycle(k,1));
                xVal2 = x(directedEdgesCycle(k,2));
                f(j) = xVal2 - xVal1;
            for k=1:length(directedEdgesCycle)
                yVal1 = y(directedEdgesCycle(k,1));
                yVal2 = y(directedEdgesCycle(k,2));
                g(j) = yVal2 - yVal1;
            for k=1:length(directedEdgesCycle)
                zVal1 = z(directedEdgesCycle(k,1));
                zVal2 = z(directedEdgesCycle(k,2));
                h(j) = zVal2 - zVal1;
        xplotdcycle = x(directedEdgesCycle(:,1));
        yplotdcycle = y(directedEdgesCycle(:,1));
        zplotdcycle = z(directedEdgesCycle(:,1));
        f = transpose(f);
        g = transpose(g);
        h = transpose(h);

Any help would be greatly appreciated, thank you.

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