gnoviceの助けを借りて、次のコードを取得しましたが、を使用してすべてのノードにエネルギーを(ランダムに)割り当て E=floor(rand(1)*10)
、最大エネルギーとノード間の距離を比較したいと思います。
N=input('no. of nodes : '); %# Number of nodes
coords = num2cell(rand(N,2)) %# Cell array of random x and y coordinates
nodes=struct('x',coords(:,1),... %# Assign x coordinates
'y',coords(:,2)); %# Assign y coordinates
plot([nodes.x],[nodes.y],'r*'); %# Plot all the nodes in red
index = randi(N,[1 2]) %# Pick two nodes at random
hold on;
plot([nodes(index).x],[nodes(index).y],'b*'); %# Plot 2 random nodes in blue
index(1) %# which node is selected first.
index(2) %# which node is selected second.
この質問は、この質問のフォローアップです。