How to find distance using loop?
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everyone,
I have to find the distance between IRS and users in 3D, for example from IRS 1 to user1, user2, user 3, user 4 and then from IRS 2 to all the users and so on. I have total 4 users and 8 IRS, I found the distances for each one using norm but now I want to find the distances using a loop so how will the loop work? New to using Matlab and I'm a little bit lost with it. Any answers would be appreciated.
%Distance of IRSs from all the users
IRS1U1=norm([3,1.5,1.5]-[6,8,1])
IRS1U2=norm([3,1.5,1.5] - [6,3,1.5])
IRS1U3=norm([3,1.5,1.5] - [6.5,5.5,1.5])
IRS1U4=norm([3,1.5,1.5] - [9,5.5,1.5])
IRS2U1=norm([6,1,1.5]-[6,8,1])
IRS2U2=norm([6,1,1.5] - [6,3,1.5])
IRS2U3=norm([6,1,1.5] - [6.5,5.5,1.5])
IRS2U4=norm([6,1,1.5] - [9,5.5,1.5])
IRS3U1=norm([8.5,1,1.5]-[6,8,1])
IRS3U2=norm([8.5,1,1.5] - [6,3,1.5])
IRS3U3=norm([8.5,1,1.5] - [6.5,5.5,1.5])
IRS3U4=norm([8.5,1,1.5] - [9,5.5,1.5])
IRS4U1=norm([10.4,2,1.5]-[6,8,1])
IRS4U2=norm([10.4,2,1.5] - [6,3,1.5])
IRS4U3=norm([10.4,2,1.5] - [6.5,5.5,1.5])
IRS4U4=norm([10.4,2,1.5] - [9,5.5,1.5])
IRS5U1=norm([3,10.5,1.5]-[6,8,1])
IRS5U2=norm([3,10.5,1.5] - [6,3,1.5])
IRS5U3=norm([3,10.5,1.5] - [6.5,5.5,1.5])
IRS5U4=norm([3,10.5,1.5] - [9,5.5,1.5])
IRS6U1=norm([6,10.5,1.5]-[6,8,1])
IRS6U2=norm([6,10.5,1.5] - [6,3,1.5])
IRS6U3=norm([6,10.5,1.5] - [6.5,5.5,1.5])
IRS6U4=norm([6,10.5,1.5] - [9,5.5,1.5])
IRS7U1=norm([8.5,10.5,1.5]-[6,8,1])
IRS7U2=norm([8.5,10.5,1.5] - [6,3,1.5])
IRS7U3=norm([8.5,10.5,1.5] - [6.5,5.5,1.5])
IRS7U4=norm([8.5,10.5,1.5] - [9,5.5,1.5])
IRS8U1=norm([10.5,9,1.5]-[6,8,1])
IRS8U2=norm([10.5,9,1.5] - [6,3,1.5])
IRS8U3=norm([10.5,9,1.5] - [6.5,5.5,1.5])
IRS8U4=norm([10.5,9,1.5] - [9,5.5,1.5])
0 件のコメント
採用された回答
rumin diao
2022 年 9 月 6 日
you can use two loops:
dist = zeros(8,4); % the matrix to save distances
for i = 1 : 8 % use this loop to get IRS1-IRS8
for j = 1 : 4 % use this loop to get 4 users
%calculate distance and save it to matrix
dist(i,j) = norm();% you can fill in the statement cause im not sure the meaning of arrays you use in 'norm';
end
end
3 件のコメント
rumin diao
2022 年 9 月 8 日
the d(i,j) you want maybe is:
sqrt(sum((IRS(:,i) - Users(:,j)).^2))
you can have a try
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!