How to convert the X & Y value in a matrix format?
3 ビュー (過去 30 日間)
古いコメントを表示
Asyran Abdullah
2018 年 9 月 26 日
コメント済み: Asyran Abdullah
2018 年 9 月 26 日
Hi, Given X and Y as follow:
area_length = 100;
area_width = area_length ;
x = round((area_length - 1) * (rand - 0) / (1 - 0) + 1);
y = round((area_width - 1) * (rand - 0) / (1 - 0) + 1);
How to convert the X & Y value into matrix format? Because i want to add a weights for make i possible to perform a shortest path.
x= ;
y= ;
weights = rand ;%-ok
G = graph(x,y,weights);
plot(G,'EdgeLabel',G.Edges.Weight);
Thanks for your help
6 件のコメント
KSSV
2018 年 9 月 26 日
YOu need to have those points to get the shortest path........do you have those points?
採用された回答
Walter Roberson
2018 年 9 月 26 日
編集済み: Walter Roberson
2018 年 9 月 26 日
Your x and y calculated like the above define the coordinates of a single point. To do shortest path, you need multiple points.
I suggest,
N = 50; %nodes
cutoff = 25;
area_length = 100;
area_width = area_length ;
x = round((area_length - 1) * (rand(N,1) - 0) / (1 - 0) + 1);
y = round((area_width - 1) * (rand(N,1) - 0) / (1 - 0) + 1);
A = squareform( pdist([x, y]) );
A(A > cutoff) = 0;
%and do any other tweaking for the A matrix
G = digraph(A);
plot(G, 'XData', x, 'YData', y);
and you can do shortest path calculations on G
With the above code, you could also use G = graph(A) to create undirected graphs, but if you do so then you would not be able to have asymmetric distance matrix. In the real world, there are cases where the transmit and receive path might not be the same.
その他の回答 (1 件)
KSSV
2018 年 9 月 26 日
Simple rand..gives you a single number....try rand(N,1) with N as desired number of points.
参考
カテゴリ
Help Center および File Exchange で Graph and Network Algorithms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!