How to map points in Vector A with many points in vector B?
1 view (last 30 days)
Show older comments
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!
Answers (1)
Steven Lord
on 17 Mar 2021
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)
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!