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 wayseach 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)
j=1;
nodePath(j,:) = directedEdges(i,:);
nodeConnection = nodePath(j,2);
while nodeConnection ~= nodePath(i,1)
[nodeSensor,nodeSensed] = find(directedEdges(:,1)==nodeConnection);
disp(directedEdges(nodeSensor,:));
j=j+1;
nodePath(j,:) = directedEdges(nodeSensor,:);
nodeConnection = nodePath(j,2);
end
^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;
end
for k=1:length(directedEdgesCycle)
yVal1 = y(directedEdgesCycle(k,1));
yVal2 = y(directedEdgesCycle(k,2));
g(j) = yVal2  yVal1;
end
for k=1:length(directedEdgesCycle)
zVal1 = z(directedEdgesCycle(k,1));
zVal2 = z(directedEdgesCycle(k,2));
h(j) = zVal2  zVal1;
end
end
xplotdcycle = x(directedEdgesCycle(:,1));
yplotdcycle = y(directedEdgesCycle(:,1));
zplotdcycle = z(directedEdgesCycle(:,1));
f = transpose(f);
g = transpose(g);
h = transpose(h);
quiver3(xplotdcycle,yplotdcycle,zplotdcycle,f,g,h,0,'MaxHeadSize',...
0.01);
end
end
Any help would be greatly appreciated, thank you.
