How to generate data for distance between nodes?

12 ビュー (過去 30 日間)
Bidyarani
Bidyarani 2023 年 2 月 16 日
回答済み: Shubham 2024 年 11 月 5 日 11:20
i want to generate data based on distance between nodes(100 nodes) in a 1 Km cell coverage. Can someone please help me. Thanks in advance.

回答 (1 件)

Shubham
Shubham 2024 年 11 月 5 日 11:20
Hi Bidyarani,
To generate data for distance between nodes in a 1km * 1km area with 100 nodes, you can follow these steps in MATLAB:
  1. Randomly place 100 nodes in a 1km * 1km grid.
numNodes = 100;
% Define the size of the area (1 km x 1 km) in meters
areaSize = 1000;
% Randomly generate node positions within the area
% Each node has an (x, y) position
nodePositions = rand(numNodes, 2) * areaSize;
2. Calculate pairwise distances between each pair of nodes.
% Initialize a matrix to store distances between nodes
distanceMatrix = zeros(numNodes);
% Compute pairwise distances
for i = 1:numNodes
for j = i+1:numNodes
% Calculate Euclidean distance between nodes i and j
distance = sqrt((nodePositions(i, 1) - nodePositions(j, 1))^2 + ...
(nodePositions(i, 2) - nodePositions(j, 2))^2);
% Store the distance in the matrix (symmetric)
distanceMatrix(i, j) = distance;
distanceMatrix(j, i) = distance;
end
end
Hope this helps.

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by