如何在matlab中得到一个大小为10M*10M的稀疏矩阵,它是正态分布的随机矩阵或均匀分布的随机矩阵。当我在下面这样做时,我得到了错误。
n = 10000000;
a = sprandn(n,n,0.1);
fid = fopen('e:/matlab/matrix/normal_1M01.mtx','w');
len = nnz(a);
fprintf(fid,'%s\n','% by taoyuan');
fprintf(fid,'%d %d %d\n',n,n,len);
[m,k,s]=find(a);
for j = 1:len
fprintf(fid,'%d %d %f\n',m(j),k(j),s(j));
end
fclose(fid);
错误如下:
??? Error using ==> rand
Maximum variable size allowed by the program is exceeded.
Error in ==> sprandn at 39
i = fix( rand(nnzwanted, 1) * m ) + 1;
Error in ==> generate at 3
a = sprandn(n,n,0.1);
顺便说一下,如何得到一个稀疏矩阵,它是幂律分布的随机矩阵,大小也是10M*10M。