How can I have one node communicate with another?
Show older comments
Hi all, I am relatively new to MATLAB, actually using this for some research for a professor and have hit brick wall. I have a biograph plotted using a sparse matrix containing n nodes with m edges. The larger the matrix, the fewer the number of edges in comparison to the number of nodes (shown below).
The problem I am having now is to have a message or packet sent from one node to another. The path taken to send the packet or message needs to be recorded as well as the index of the source and destination node of one to the other.
To give an example, a message is sent from node 1 to node 14 along the following path 1 --> 5 --> 12 --> 14
I need to be able to store the index of node 5 in a table linked to node 1, the index of node 1 and node 12 in a table linked to node 5, the index of node and 14 in a table linked to node 12 and the index of node 12 in a table linked to node 14.
The code I've already come up with is below.
if true
% %Create Matrix
matrix = [1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ;
1 1 1 1 1 0 0 0 0 1 0 1 0 0 0 ;
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 ;
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 ;
1 0 0 0 0 1 1 1 1 0 0 0 0 0 0 ;
1 0 0 0 0 1 1 1 1 0 1 0 0 0 0 ;
0 0 0 0 1 0 0 0 0 1 0 1 1 0 0 ;
0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 ;
0 0 0 0 1 0 0 0 0 1 0 1 0 1 1 ;
0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 ;
0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 ;
0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 ];
%Make matrix sparse
matrix = sparse(matrix);
%Lower triangular matrix to ignore duplicate connections (eg {2,1 and 1,2}
%one will be ignored)
matrix= tril(matrix+matrix');
%Creation of Boigraph Object using matrix
h = view(biograph(matrix,[],'ShowArrows', 'off','ShowWeights','on'));
%Traversal of graph using BFS at a depth of n from node x
node_idxs1 = graphtraverse(matrix,2,'Method','BFS','directed',false,'depth',1);
%Color nodes at n generations
set(h.Nodes(node_idxs1),'Color',[1 0.4 0.4]);
%View graph
h.view;
end
Any help would be appreciated and I am open to changing everything if needs be. If you need more info, just let me know. Thanks!
2 Comments
Dileon
on 5 Mar 2013
Cedric
on 5 Mar 2013
How do you compute/determine/store the path 1-->5-->12-->14?
How would you use then a "table" that would associate neighboring elements from the path with each one of its elements? I'm asking because there are plenty of ways to store this information (array, cell array, struct array, function extracting neighbors from the path, etc).
Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!