LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
cyclicGraph.m
1function graph = cyclicGraph(numVertices)
2% This is an alternative topologyFcn for NetworkGenerator. It takes in
3% an integer number of vertices and returns a MATLAB digraph object
4% representing a cyclic directed graph.
5
6 graph = digraph;
7 graph = addnode(graph, numVertices);
8 if numVertices < 1
9 error('cyclicGraph:nonPositiveVertices', 'numVertices must be positive');
10 elseif numVertices == 1
11 graph = addedge(graph, 1, 1);
12 else
13 for i = 1 : numVertices - 1
14 graph = addedge(graph, i, i + 1);
15 end
16 graph = addedge(graph, numVertices, 1);
17 end
18end