is it a correct output of adjacency matrice?
1 次查看(过去 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!