MATLAB: Distance between randomly selected nodes

distance between two randomly selected nodes

for i=1:1:n
temp_rand=rand;
if(temp_rand<= some condition)
count_n=count_n+1;
S(i).type='C';
C(cc).xd=S(i).xd;
C(cc).yd=S(i).yd;
plot(S(i).xd,S(i).yd,'*');
cc=cc+1;
In the above code some nodes are selected from randomly distributed nodes which satisfy the temp_rand condition. Please anyone help me how to find out distance between these randomly nodes only.

Best Answer

xt = [CC.xd]; yt = [CC.yd];
distances = squareform( pdist([xt(:), yt(:)]) );