MATLAB Answers

How can I find distances between 100 points such that I have a set of distances of each point from rest of the points.

조회 수: 2(최근 30일)
Tamoor Shafique
Tamoor Shafique 2021년 1월 2일
댓글: Tamoor Shafique 2021년 1월 3일
Hi Everyone,
I have distributed 100 points randomly in a 100x100x100 m3 3D space. I want to find distance of each point from rest of 99 points such that I have a distance set of 4950 different values. so the distance of 1st node from resy 99 nodes and then distance of 2nd node from rest 98 nodes and so on.
I cannot change the style of the code since I have values saved in these variables.
I have following code:
Close all
Clear all
n=100;
xm=100;
ym=100;
zm=100;
x=0;
y=0;
z=0;
for i=1:1:n
for j=1:1:i
for k=1:1:j
if (i==j && j==k & k==i) % so I dont get 100x100x100 different values and only 100 values with x,y,z coordinates.
S(i).xd=(1,1)*xm; %I cannot change this
XR(i)=S(i).xd;
S(j).yd=rand(1,1)*ym;
YR(j)=S(j).yd;
S(k).zd=rand(1,1)*zm;
ZR(k)=S(k).zd;
Points=[XR;YR;ZR]
end
end
end

답변(1개)

Ameer Hamza
Ameer Hamza 2021년 1월 2일
Just use pdist() function
X = [..]; % create 100x3 matrix
dists = pdist(X)
  댓글 수: 3
Tamoor Shafique
Tamoor Shafique 2021년 1월 3일
Please see attached. I am not good with Matlab if there are esier ways I don't mind adapting as long as it gives me distribution of nodes in full 100x100x100 network and then splits it into 27 sub cubes so i can get local info about each subnode like data in 27 sets.

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

Community Treasure Hunt

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

Start Hunting!

Translated by