matlab adjacency()
时间: 2023-11-02 11:52:51 浏览: 108
The adjacency() function in MATLAB is used to create an adjacency matrix from a graph. An adjacency matrix is a matrix that represents the connections between nodes in a graph. The rows and columns of the matrix represent the nodes, and the entries represent the edges between them.
Syntax:
adjacency_matrix = adjacency(graph)
The input argument graph can be either a graph object or a matrix. If it is a graph object, the function extracts the adjacency matrix from the graph. If it is a matrix, the function assumes that it represents an undirected graph and creates the adjacency matrix.
Example:
Consider the following undirected graph:
![image.png](attachment:image.png)
We can create an adjacency matrix for this graph using the adjacency() function as follows:
graph = [0 1 1 0 0; 1 0 1 1 0; 1 1 0 1 1; 0 1 1 0 1; 0 0 1 1 0];
adjacency_matrix = adjacency(graph)
The resulting adjacency matrix will be:
![image-2.png](attachment:image-2.png)
阅读全文