0

I want to use MATLAB to create the adjacency matrix for the following undirected graph data in this link.

When I apply "graph" function, I get the error that the matrix has duplicate edges. When I investigated the uniqueness of rows, all the rows were unique. When I tried to find the rows which are mirrored of each other (because in undirected graph still they are considered as duplication), I did not find any mirrored row. So, I am asking this question in here and I highly appreciate it, if someone can help me to get the adjacency matrix for this particular data.

The matrix "data" which has two columns contains "From-To" information of nodes. So, I firstly used the following command to get the adjacency matrix:

% Create a graph object from the node numbers
G = graph (data (:,1), data (:,2));

% Find the adjacency matrix of the graph
A = adjacency (G);

Then, I get this error message in MATLAB:

Error using matlab.internal.graph.MLGraph
Duplicate edges not supported.

Error in matlab.internal.graph.constructFromEdgeList (line 125)
G = underlyingCtor(double(s), double(t), totalNodes);

Error in graph (line 287)
                matlab.internal.graph.constructFromEdgeList(...

Then, I tried this to find the rows which are duplicated

[~, ia, ic] = unique (data,'rows');

% Find the indices of the duplicate rows of A
dupRows = setdiff (1:size (A,1), ia (accumarray (ic,1)<=1));

Then, I did not get any rows which are duplicated.

Then I tried the following code to find the rows which are mirrored of each other :

[~, mirror_idx] = ismember (data,fliplr (data),'rows');
data (mirror_idx,:) = [];

and it literally eliminated all the rows of the matrix "data", (i.e. data=[])

AMGEO
  • 13
  • 4
  • 1
    We would need to see some code showing how you load the data and how you create the graph. – beaker May 16 '23 at 03:21
  • Sure, I included the used codes in the question. – AMGEO May 16 '23 at 17:56
  • I wouldn't expect the adjacency matrix to be created at all, since the error is in the constructor of the Graph object. Does `data` have the size you expect? Does `data_u = unique(data,'rows');` give you a different size? – beaker May 16 '23 at 19:41
  • 1
    Not sure where this error is coming from. I was able to download the data from the link, import it using `data = readmatrix('CA-GrQc.txt');` (resulting a 28980x2 matrix), and then make the graph and adjacency matrix using the same code you wrote above (`G = graph((data(:,1), data(:,2)); A = adjacency(G);` worked fine for me). – magnesium May 18 '23 at 04:42
  • Thanks, since now I know it actually works, it's a big help. What version of MATLAB you are using? I tried with 2017a. – AMGEO May 20 '23 at 01:43
  • `readmatrix` was added in 2019a. This is why posting your code is important. Also, people are not notified that you responded to them unless you tag them like @AMGEO – beaker May 21 '23 at 22:47

0 Answers0