- toeplitz: https://www.mathworks.com/help/matlab/ref/toeplitz.html
- fliplr: https://www.mathworks.com/help/matlab/ref/fliplr.html
- gplot: https://www.mathworks.com/help/matlab/ref/gplot.html
Build and visualize a circulant graph
조회 수: 6 (최근 30일)
이전 댓글 표시
Hello; l need to code and plot a circulant graph as it is illustrated in the two figures below.any suggestions ?
댓글 수: 0
답변 (1개)
Jaynik
2024년 8월 26일
There is no direct function to plot "circulant" graphs in MATLAB. Though you can create a plot from using other available functions. Here is one of the approach you can use:
% Define the number of vertices
n = 12;
v = [0 1 1 0 1 0 0 1 0 1 0 1]; % Define the first row with the connections
C = toeplitz([v(1) fliplr(v(2:end))], v); % Create the circulant matrix
C = [C, ones(n, 1); ones(1, n), 0]; % Add a row and column for the central vertex
% Define the coordinates for the vertices
theta = linspace(0, 2*pi, n+1);
x = cos(theta(1:end-1));
y = sin(theta(1:end-1));
coords = [x' y'; 0 0];
% Plot the graph
gplot(C, coords, '-o');
axis equal;
title('Circulant Graph');
Here, we use the toeplitz and fliplr functions to create the "circulant" matrix by defining the first row. We then define the coordinates for the vertices and use the gplot function is used to finally plot the graph.
You can refer to the following documentation to learn more about these functions:
You can also explore the following file exchange link to generate a circular matrix: https://www.mathworks.com/matlabcentral/fileexchange/22858-circulant-matrix
Hope this helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!