As helped by gnovice I got following code, but now I want to assign energy (randomly) to every nodes using E=floor(rand(1)*10)
and also want to compare for maximum energy and what is distance between them?
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.
this question is follow up of this question.