convert edge list to adjacency matrix

1 回表示 (過去 30 日間)
Sujatha
Sujatha 2014 年 7 月 1 日
回答済み: Walter Roberson 2017 年 3 月 27 日
How to convert an edge list with 5000000 nodes to adjacency matrix in Matlab. I tried the following code:
fid = fopen('C:\myfile.txt', 'r');
E = fscanf(fid, '%g %g', [2 inf]);
E=E';
adj=sparse(E(:,1),E(:,2),1);
adj=full(adj);
fclose(fid);
I am getting memory error. Is there any way out?
  1 件のコメント
farouk benseghir
farouk benseghir 2017 年 3 月 27 日
i have same prblm any soulution??

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 27 日
A non-sparse adjacency matrix with 5 x 10^6 members in it would require a minimum of (5 * 10^6)^2 = 25 * 10^12 bytes, which would be about 22 3/4 petabytes. If you have that much memory available, then you should change your code from
adj=sparse(E(:,1),E(:,2),1);
to
adj = sparse(E(:,1), E(:,2), true);
to create a sparse logical array; then when you do the full() it will be a logical array that is created instead of a double array.
Note: many of the common algorithms you would want to apply to such as matrix will likely require that the data be converted to floating point, and will probably need temporary storage as large as that floating point array, so if you run out of memory using sparse() the way you are calling it now, chances are good that using a logical array instead of a double array will not reduce your memory problems enough to be able to do useful work.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by