distance between randomly selected nodes
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    rem ng
 el 18 de Mzo. de 2019
  
    
    
    
    
    Respondida: Walter Roberson
      
      
 el 18 de Mzo. de 2019
            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.
2 comentarios
  Geoff Hayes
      
      
 el 18 de Mzo. de 2019
				rem - so you want to find the distances between all nodes in the C matrix? Or do you want to find the distance between a different set of nodes?
Respuesta aceptada
  Walter Roberson
      
      
 el 18 de Mzo. de 2019
        xt = [CC.xd]; yt = [CC.yd]; 
distances = squareform( pdist([xt(:), yt(:)]) );
0 comentarios
Más respuestas (1)
  Geoff Hayes
      
      
 el 18 de Mzo. de 2019
        rem - wouldn't the distances be calculated something like the following
distancesBetweenNodes = zeros(length(C)); % square matrix
for k = 1:length(C)
    for j = k+1:length(C)
        dist = sqrt((C(k).xd - C(j).xd)^2 + (C(k).yd - C(j).yd)^2); % use your own distance measure here
        distancesBetweenNodes(k,j) = dist;
        distancesBetweenNodes(j,k) = dist; % matrix is symmetric
    end
end
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


