unmesh
Converts a list of mesh edges to a graph adjacency matrix and node coordinates.
Category: Mathematics > Sparse Matrices
Syntax
[A, xy] = unmesh(E)
Returns the adjacency matrix A and node coordinates xy for the edge list E.
Description
Segments that share an end point are connected through the same node: two end points with identical coordinates become one node. The pair A, xy is exactly what gplot needs, so a drawing given as loose line segments can be turned into a graph and analyzed with sparse matrix tools.
Input arguments
Em-by-4 matrix; each row[x1 y1 x2 y2]is one edge, given by the coordinates of its two end points.
Output arguments
A- Symmetric
n-by-nadjacency matrix, withA(i,j) = 1when nodesiandjshare an edge. xyn-by-2 matrix with the coordinates of the distinct end points, numbered in order of first appearance.
Example
A triangle from three segments
E = [0 0 1 0; 1 0 0 1; 0 1 0 0];
[A, xy] = unmesh(E);
full(A)
xy
Output
ans = 3×3
2 -1 -1
-1 2 -1
-1 -1 2
xy = 3×2
0 0
0 1
1 0