How to create (x,y) matrix in complete graph in matlab
2 次查看(过去 30 天)
显示 更早的评论
Hi I have write code for make complete graph with n vertices. and E= n*(n-1)/2. This generated graph has to display its adjacency connections in a 2xN matrix.
% Complete Graph
% N arithos komvon
% E = edges
close all
n = input ('Dose ton arithmo ton konvon: ');
E = (n*(n-1)/2);
theta = linspace(0,2*pi,n+1).';
theta(end)=[]; % 0 = 2pi so...
r = n;
cor = [r*cos(theta) r*sin(theta)]; % x coordinates of points
axes('nextplot','add')
while size(cor,1) > 1
cor_pt = repmat(cor(1,:),size(cor,1)-1,1); % point being connected to others
cor(1,:) = [];
for i = 1:size(cor_pt,1)
line([cor_pt(i,1),cor(i,1)],[cor_pt(i,2),cor(i,2)],'marker','.','markersize',20)
end
end
0 个评论
回答(1 个)
Steven Lord
2020-10-15
If this is not a homework assignment where you're expected to write the code to plot a graph yourself, just use the graph function included in MATLAB. You can call it with the adjacency matrix of your graph and then plot it.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!