Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Graph::createGraphFromMatrix

Transfers a squared matrix into a directed graph

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

Graph::createGraphFromMatrix(M)

Description

Graph::createGraphFromMatrix(M) generates a directed Graph where each mi, j in the matrix defines an edge fromi to j. The value of the cell defines the weight of the resulting edge.

The vertices of the generated graph are labeled with the numbers 1 to n, where n defines the column/row-dimension of the matrix. Since the matrix has to be squared, n stays the same.

Examples

Example 1

A matrix is defined and the resulting squared matrix is transfered into a Graph.

a := matrix([[3, 2, 4], [2, 3, 6], [4, 8, 3]]);
G := Graph::createGraphFromMatrix(a):
Graph::printGraphInformation(G)

Vertices: [1, 2, 3]
Edges: [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3\
, 3]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: [1, 1] = 3, [1, 2] = 2, [1, 3] = 4, [2, 1] = 2, [2, 2] = 3, \
[2, 3] = 6, [3, 1] = 4, [3, 2] = 8, [3, 3] = 3 (other existing edges have \
no weight)
Edge costs: no edge costs.
Adjacency list (out): 1 = [1, 2, 3], 2 = [1, 2, 3], 3 = [1, 2, 3]
Adjacency list (in): 1 = [1, 2, 3], 2 = [1, 2, 3], 3 = [1, 2, 3]
Graph is directed.

Parameters

M

A matrix

Return Values

Graph

Was this topic helpful?