How can I connect 25 nodes with 50 connections?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Linda Grafen
il 4 Ago 2017
Risposto: Elizabeth Reese
il 10 Ago 2017
I have 25 nodes that need 50 (random) connections. Below my code, any suggestions?
figure;
load('usborder.mat','x','y','xx','yy');
rng(6,'twister')
nStops = 25;
stopsLon = zeros(nStops,1);
stopsLat = stopsLon;
n = 1;
while (n <= nStops)
xp = rand*1.5;
yp = rand;
if inpolygon(xp,yp,x,y)
stopsLon(n) = xp;
stopsLat(n) = yp;
n = n+1;
end
end
plot(x,y,'k--');
hold on
plot(stopsLon,stopsLat,'xr')
hold off
0 Commenti
Risposta accettata
Elizabeth Reese
il 10 Ago 2017
There are a couple of ways to do this. One way is to use randi to generate two integers between 1 and 25. They will act as indexes into your list of nodes. You can then use these numbers to index into your stopsLon and stopsLat and connect the nodes at those two indexes. If you are concerned about self-loops or having only unique paths, then you can create a 25x25 connectivity matrix or similar structure to keep track of which connections you have already made.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Debugging and Analysis in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!