How to make a line between random nodes connection ?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Asyran Abdullah
le 24 Août 2018
Commenté : Asyran Abdullah
le 24 Août 2018
Hi guys,
How to make a connection between random nodes and select 1 of them as a cluster head?
numNodes=10;
p = rand(numNodes,2);
labels = cellstr( num2str([1:numNodes]') );
plot(p(:,1),p(:,2),'rx')
text(p(:,1), p(:,2), labels, 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right')
The figure
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/194320/image.png)
0 commentaires
Réponse acceptée
Walter Roberson
le 24 Août 2018
numNodes = 10;
numEdge = 15; %maximum, really. Random edges are generated and there could be duplicates
p = rand(numNodes,2);
st = unique( sort( randi(numNodes, numEdge, 2), 2), 'rows');
G = graph(st(:,1), st(:,2));
gp = plot(G);
gp.XData = p(:,1); gp.YData = p(:,2);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!