我认为问题是32/64位相关。如果你有一个32位的处理器,你最多可以编址
2^32 = 4.294967296e+09
元素。如果你有一个64位处理器,这个数字上升到
2^64 = 9.223372036854776e+18
不幸的是,这充其量模糊,我的理由,MATLAB不使用此齐全。要找出利用Matlab实际使用的范围,发出以下命令:
[~,maxSize] = computer
在32位系统,这给
>> [~,maxSize] = computer
maxSize =
2.147483647000000e+09
>> log2(maxSize)
ans =
3.099999999932819e+01
和64位系统上,它给
>> [~,maxSize] = computer
maxSize =
2.814749767106550e+14
>> log2(maxSize)
ans =
47.999999999999993
很显然,在32位系统上,Matlab只使用31位来寻址元素,这给了你的上限。
If anyone can clarify why Matlab only uses 31 bits on a 32-bit system, and only 48 bits on a 64-bit system, that'd be awesome :)
在内部,Matlab的总是使用线性索引来访问元素的阵列(它可能只是使用C语言风格的阵列或左右),这意味着为您adj矩阵,它的最后一个元素是
finEl = nNodes*nNodes = 2.54016e+09
不幸的是,这比31位的最大寻址大。因此,在32位的系统上,
>> adj(end) = 1;
??? Maximum variable size allowed by the program is exceeded.
而此命令的64位系统上在所有不会产生问题。
你将不得不使用一种变通方法在32位系统上:
nNodes = 50400;
% split sparse array up into 4 pieces
adj{1,1} = sparse(nNodes/2,nNodes/2); adj{1,2} = sparse(nNodes/2,nNodes/2);
adj{2,1} = sparse(nNodes/2,nNodes/2); adj{2,2} = sparse(nNodes/2,nNodes/2);
% assign or index values to HUGE sparse arrays
function ret = indHuge(mat, inds, vals)
% get size of cell
sz = size(mat);
% return current values when not given new values
if nargin < 3
% I have to leave this up to you...
% otherwise, assign new values
else
% I have to leave this up to you...
end
end
% now initialize desired elements to 1
adj = indHuge(adj, sub2ind([nNodes nNodes], ind, ind + 1), 1);
我只是有想法,投这一切都成真类,这样就可以使用更直观的语法。 ..但是这比我现在有更多的时间:)