is it a correct output of adjacency matrice?

1 vue (au cours des 30 derniers jours)
HASAN JAHANIFAR
HASAN JAHANIFAR le 13 Juil 2022
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)

Réponses (1)

Piyush Patil
Piyush Patil le 6 Oct 2023
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.

Catégories

En savoir plus sur Graph and Network Algorithms dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by