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.

Antworten (1)

Walter Roberson
Walter Roberson am 14 Dez. 2022

0 Stimmen

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)

Kategorien

Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 14 Dez. 2022

Beantwortet:

am 14 Dez. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by