how to code in matlab struct form to find the distances of nodes randomly selected from a randomly distrbuted nodes. pliz help
in the given code some nodes are selected based on some random number generated by nodes from i nodes and one struct matrix is formed for the new nodes and want to find distances for those new selected nodes. pliz help

 채택된 답변

KSSV
KSSV 2019년 2월 1일

0 개 추천

Read about pdist and pdist2. If you have coordinates(x1,y1) and (x2,y2) you may straight away use distance formula:
d = sqrt((x2-x1).^2+(y2-y1).^2)

댓글 수: 3

You can also use hypot which supposedly is more reliable for extreme cases than using sqrt(dx.^2 + dy.^2) directly.
d = hypot(x2-x1, y2-y1);
madhan ravi
madhan ravi 2019년 2월 1일
편집: madhan ravi 2019년 2월 1일
+1 Guillaume! , hypot's accuracy is higher.
rem ng
rem ng 2019년 2월 2일
thanks all for your help !!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

태그

질문:

2019년 2월 1일

댓글:

2019년 2월 2일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by