convert edge list to adjacency matrix
조회 수: 2 (최근 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!