how to find a route from node to node till reach the destination
3 views (last 30 days)
Show older comments
Hi, I have problem in finding the route. find one by one till reach the destination. the criteria is to get the nearest node,once its find, that nearest node will be a source node and again find the nearest one.here's the code:
clear
close all
home_size=25;
radius=10;
No_Nodes =100;
x=0;
y=0;
w=22;h=7;
Cell_Range = 10;
Node_Loc = round(home_size*rand(No_Nodes, 2));
[temp,Source_Loc]=min(Node_Loc(:,1));
[tmp,Dest_Loc]=max(Node_Loc(:,1));
plot(Node_Loc(Source_Loc,1),Node_Loc(Source_Loc,2),'or');hold on;
plot(Node_Loc(Dest_Loc,1),Node_Loc(Dest_Loc,2), 'ok'); hold on;
hold on
Source_Loc=Node_Loc(Source_Loc,:)
Dest_Loc=Node_Loc(Dest_Loc,:)
SLoc=Source_Loc;
Sarah=[]; %j=1;
SPts=Node_Loc; [Ck Indx1]=min(SPts(:,1));
SPts(Indx1,:)=[];
for i=1:length(SPts(:,1))
for SLoc ~= Dest_Loc
plot(SPts(i,1), SPts(i,2), '.b'); hold on; axis equal;
Dist(i)=sqrt((SPts(i,1)-SLoc(1,1))^2+(SPts(i,2)-SLoc(1,2))^2);
Sarah=[Sarah Dist(i)];
[Minmm Indx]=min(Sarah);
plot([SLoc(1,1);SPts(Indx,1)],[SLoc(1,2);SPts(Indx,2)],'g');hold on
SLoc=[SPts(Indx,1),SPts(Indx,2)]
end
end
I hope somebody can help me on this. thank you very much.
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!