convert edge list to adjacency matrix
1 次查看(过去 30 天)
显示 更早的评论
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!