How to map points in Vector A with many points in vector B?
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I have two row vectors with the same size.
A = randi(100,1,100); % Elements of A represent cities
B = randi([101, 200],1,100); % Elements of B represent some other cities
Is it possible to map each element in A with many elements in B ? For example, I want to connect A (i) with, let's say, three cities in B. Where i is a city in vector A.
Is it doable under some constraints?
Thanks!
4 个评论
Waseem AL Aqqad
2021-3-16
Hi Rayan,
For the case of one to many structure or mapping, the two networks or graphs cannot have the same number of nodes. Otherwise, half the number of nodes in one of the graphs would be considered autonomous nodes, that is, independent nodes.
So, if graph G has 8 nodes, graph H should have c * numnodes(G) nodes, where c is a positive integer. Let's assume that c = 2, then numnodes(H) = 16. Another constraint would be that each node i in G should be mapped to the same number of nodes in H. In our example, each node i in G should be mapped to two nodes in H.
The staff at Mathworks developed an amazing toolbox for graph theory, so you might want to check this page to help you have a better understanding.
回答(1 个)
Steven Lord
2021-3-17
You can do this using an adjacency matrix:
A = [1 1 0; 0 0 1; 1 0 1];
D = digraph(A);
D.Nodes.Name = ["Boston"; "New York"; "Los Angeles"]
plot(D)
Or you could build an empty graph or digraph and use addedges and addnodes to built it up incrementally.
D2 = digraph;
D2 = addedge(D2, "Boston", "Boston");
D2 = addedge(D2, "Boston", "New York");
D2 = addedge(D2, "New York", "Los Angeles");
D2 = addedge(D2, "Los Angeles", "Boston");
D2 = addedge(D2, "Los Angeles", "Los Angeles")
plot(D2)
另请参阅
类别
在 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!