Clear Filters
Clear Filters

I'm trying to plot a map of downtown Lincoln NE with streetweights for a project but continue to get an error saying my adjacency matrixes must be square.

1 view (last 30 days)
With 56 nodes, it is unrealistic to have 56 entries for each node correct? because there are only 4 possible ways a street intersection can go. The 0 values represent an edge of the control area and the 99999 values represent a one-way that cannot be driven on in that direction. order of direction is up, right, down, left.
streetCorners = {'9th & Q' '9th & P' '9th & O' '9th & N' '9th & M' '9th & L' '9th & K' '10th & Q' '10th & P' '10th & O' '10th & N' '10th & M' '10th & L' '10th & K' '11th & Q' '11th & P' '11th & O' '11th & N' '11th & M' '11th & L' '11th & K' '12th & Q' '12th & P' '12th & O' '12th & N' '12th & M' '12th & L' '12th & K' '13th & Q' '13th & P' '13th & O' '13th & N' '13th & M' '13th & L' '13th & K' '14th & Q' '14th & P' '14th & O' '14th & N' '14th & M' '14th & L' '14th & K' '16th & Q' '16th & P' '16th & O' '16th & N' '16th & M' '16th & L' '16th & K' '17th & Q' '17th & P' '17th & O' '17th & N' '17th & M' '17th & L' '17th & K'};
streetWeight = [0 99999 30260 0;99999 7680 25470 0;99999 21030 26920 0;99999 99999 27710 0;99999 4060 26230 0;99999 99999 25180 0;99999 15370 0 0;0 99999 99999 5280;23890 7760 99999 99999;23720 19560 99999 21030;26090 99999 99999 3820;25400 4080 99999 99999;25540 99999 99999 7340;21160 13870 0 99999;0 99999 2150 8400;99999 6900 2110 99999;99999 13040 2900 19560;99999 99999 3540 4320;99999 4450 2980 99999;99999 99999 2330 11870;99999 16060 0 99999;0 99999 99999 10340;3360 7480 99999 99999;2960 19760 99999 19040;3360 99999 99999 4040;3110 5160 99999 99999;2670 99999 99999 12240;2260 14740 0 99999;0 99999 3600 9450;99999 7740 2780 99999;99999 20490 3750 19760;99999 99999 4360 3060;99999 5230 5410 99999;99999 99999 4530 13260;99999 16840 0 99999;0 99999 99999 10910;3760 6640 99999 99999;2630 21150 99999 20490;1970 99999 99999 4400;4050 4640 99999 99999;3610 99999 99999 14240;2850 16550 0 99999;0 99999 5310 11300;99999 6370 6400 99999;99999 24930 7320 21410;99999 99999 7500 5620;99999 2980 7770 99999;99999 99999 8200 15000;99999 16610 0 99999;0 0 99999 13420;8300 0 99999 99999;8900 0 99999 24930;12090 0 99999 2830;13780 0 99999 99999;11620 0 99999 15030;11010 0 0 99999];
G = digraph(streetWeight,streetCorners);
map = plot(G);

Answers (1)

Aritra
Aritra on 23 Mar 2023
Hi,
As per my understanding you are trying to plot a map for your project.
To solve this, you are using the “digraph” function. However, you are encountering an error which says:
“Adjacency matrix must be square.”
The digraph function creates a directed graph using a square adjacency matrix.
  • For logical adjacency matrix, the generated graph has no edge weights.
  • For nonlogical adjacency matrix, the graph has edge weights. The location of nonzero entry specifies an edge for the graph, and the weight od the edge is equal to the value of the entry.
You can refer to the below code snippet for more details:
streetCorners = {'9th & Q' '9th & P' '9th & O' '9th & N'};
streetWeight = [0 99999 30260 0;99999 7680 25470 0;99999 21030 26920 0;99999 99999 27710 0];
G = digraph(streetWeight,streetCorners);
map = plot(G);
For detail, please see this MathWorks documentation below for more information on “digraph”:

Categories

Find more on Graph and Network Algorithms in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!