is it a correct output of adjacency matrice?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
I have a list of edges, and nodes. could you please let me know is it a correct method to show the adjancy matrice? I have attached the csv files accordingly as well.
nodes_info = readtable('nodelist.csv');
edges_info = readtable('edgelist.csv');
G = graph();
G = G.addnode(string(nodes_info.Id));
G = G.addedge(string(edges_info.Source), string(edges_info.Target));
A = adjacency(G,'weighted');
figure
spy(A)

댓글 수: 0
답변 (1개)
Piyush Patil
2023년 10월 6일
Hello Hasan,
As per my understanding, you have created an adjacency matrix by using the data present in "edgelist.csv" and "nodelist.csv" file and you want to know if this is the correct way to create an adjacency matrix.
By looking at the "edgelist.csv" file, it seems that you are having the data for directed graph whereas "graph" function in MATLAB is used for undirected graphs.
Although, rest of your code is correct, I would suggest you use digraph function instead of "graph" function. "digraph" function is used in case of directed graphs.
Please replace line number 3 of ypur code which is -
G = graph();
with line
G = digraph();
Rest of the code is correct.
I hope this resolves the issue you were having.
댓글 수: 0
참고 항목
카테고리
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!