define a 15X15 matrix for a graph.

need to create a 15X15 matrix for a graph. with diagonal values as 1 and adjacent edges for a graph AS 1 AND all the other values of the matrix as zeros.

Answers (1)

Use graph() or digraph() with the s, t input form. s should contain a list of edge source node numbers and t should contain the matching edge target node numbers. The s and t should also a section listing all of the node numbers and t the same list, so that an edge is built between each node and itself.
Once this is done, ask for the adjacency matrix of the graph() object.
There are certainly other ways to create the array. For example if you have the s and t as described then
accumarray([s(:),t(:)], 1)

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Tags

Asked:

on 14 Dec 2022

Answered:

on 14 Dec 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!