how to create matrix with coordinates and calculate distance?

n = 3; ri=0.9
source = 1;
destination = 3;
Link=(n*(n-1))/2;
c=2^Link;
NN = toeplitz(Link+1:-1:2)
mask = logical(fliplr(diag(ones(1,Link-1),-1)));
NN(mask) = 1;
for c = 0:2^Link-1
l = bitget(c, NN)
end
i have this type matrix code. l is the matrix.how to calculate distance.
i = 1 :n
j = i+1:n
D(i,j) = sqrt((x(i)-x(j))^2 + (y(i)-y(j))^2);
please help to calculate distance.

 채택된 답변

Simon Chan
Simon Chan 2021년 7월 9일

0 개 추천

[Ny, Nx] = size(l);
[X,Y]=meshgrid(1:Nx,1:Ny);
D = sqrt(X.^2 + Y.^2)

댓글 수: 6

D =
0 2.2361 3.1623
2.2361 0 3.6056
3.1623 3.6056 0
i want this type of matrix and also for loop. please help me
Suppose it is a 3x3 matrix,
then the following scripts should work
[X,Y]=meshgrid(1:3,1:3);
D = sqrt(X.^2 + Y.^2)
I try it again:
[Ny, Nx] = size(l);
[X,Y]=meshgrid(1:Nx,1:Ny);
D = sqrt(X.^2 + Y.^2)
D =
1.4142 2.2361 3.1623
2.2361 2.8284 3.6056
3.1623 3.6056 4.2426
As your request:
D = zeros(3,3);
for r = 1:3
for s = 1:3
if r~=s
D(r,s) = sqrt(r^2+s^2);
end
end
end
A for loop created just before you submit the comment.
do you now interference.
n = 3. if three nodes are 1,2,3.
2 is interfering node. 1 is source node and 3 is destination node.
for example n = 10
for a network of 10 nodes where n1 is the source and n10 is the destination, all permutations of m or fewer elements of 2,3,....,9 form potential paths when m represents the limit on intermediate nodes. The number of paths with m intermediate nodes
how to calculate interference
please any idea and help me to calculate
Sorry, no idea about interference. You may search previous questions to see whether you can get any solution from others.

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

추가 답변 (1개)

ankanna
ankanna 2021년 7월 9일

0 개 추천

ok sir thank you for your quick response

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품

릴리스

R2016a

질문:

2021년 7월 9일

답변:

2021년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by