我们如何在matlab中处理大型矩阵(大于10000x10000)
在我的程序中,我面临一些大于 10000x10000 的矩阵。 我无法转置或反转它们,如何克服这个问题?
??? Error using ==> ctranspose
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname1 at 70
B = cell2mat(C(:,:,s))';
Out of memory. Type HELP MEMORY for your options.
Example 1: Run the MEMORY command on a 32-bit Windows system:
>> memory
Maximum possible array: 677 MB (7.101e+008 bytes) *
Memory available for all arrays: 1602 MB (1.680e+009 bytes) **
Memory used by MATLAB: 327 MB (3.425e+008 bytes)
Physical Memory (RAM): 3327 MB (3.489e+009 bytes)
* Limited by contiguous virtual address space available.
** Limited by virtual address space available.
Example 2: Run the MEMORY command on a 64-bit Windows system:
>> memory
Maximum possible array: 4577 MB (4.800e+009 bytes) *
Memory available for all arrays: 4577 MB (4.800e+009 bytes) *
Memory used by MATLAB: 330 MB (3.458e+008 bytes)
Physical Memory (RAM): 3503 MB (3.674e+009 bytes)
=================================================== ============================
memory
% Maximum possible array: 1603 MB (1.681e+009 bytes) *
% Memory available for all arrays: 2237 MB (2.346e+009 bytes) **
% Memory used by MATLAB: 469 MB (4.917e+008 bytes)
% Physical Memory (RAM): 3002 MB (3.148e+009 bytes)
I have used sparse for C.
B = cell2mat(C);
clear C %# to reduce the allocated RAM
P=B\b;
Name Size Bytes Class Attributes
B 5697x5697 584165092 double sparse, complex
C 1899x1899 858213576 cell
b 5697x1 91152 double complex
==============================================================================
??? Error using ==> mldivide
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname at 82
P=B\b;
==============================================================================
编辑:27.05.11
Name Size Bytes Class Attributes
C 997x997 131209188 cell
B 2991x2991 71568648 single complex
Bdp 2991x2991 143137296 double complex
Bsparse 2991x2991 156948988 double sparse, complex
Bdp=double(B);
Bsparse=sparse(Bdp);
我使用单精度,女巫给出了与双精度相同的精度
更好,我说得对吗?
In my program I am faced with some matrices that are larger than 10000x10000.
I cannot transpose or inverse them, how can this problem be overcome?
??? Error using ==> ctranspose
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname1 at 70
B = cell2mat(C(:,:,s))';
Out of memory. Type HELP MEMORY for your options.
Example 1: Run the MEMORY command on a 32-bit Windows system:
>> memory
Maximum possible array: 677 MB (7.101e+008 bytes) *
Memory available for all arrays: 1602 MB (1.680e+009 bytes) **
Memory used by MATLAB: 327 MB (3.425e+008 bytes)
Physical Memory (RAM): 3327 MB (3.489e+009 bytes)
* Limited by contiguous virtual address space available.
** Limited by virtual address space available.
Example 2: Run the MEMORY command on a 64-bit Windows system:
>> memory
Maximum possible array: 4577 MB (4.800e+009 bytes) *
Memory available for all arrays: 4577 MB (4.800e+009 bytes) *
Memory used by MATLAB: 330 MB (3.458e+008 bytes)
Physical Memory (RAM): 3503 MB (3.674e+009 bytes)
==============================================================================
memory
% Maximum possible array: 1603 MB (1.681e+009 bytes) *
% Memory available for all arrays: 2237 MB (2.346e+009 bytes) **
% Memory used by MATLAB: 469 MB (4.917e+008 bytes)
% Physical Memory (RAM): 3002 MB (3.148e+009 bytes)
I have used sparse for C.
B = cell2mat(C);
clear C %# to reduce the allocated RAM
P=B\b;
Name Size Bytes Class Attributes
B 5697x5697 584165092 double sparse, complex
C 1899x1899 858213576 cell
b 5697x1 91152 double complex
==============================================================================
??? Error using ==> mldivide
Out of memory. Type HELP MEMORY for your options.
Error in ==> programname at 82
P=B\b;
==============================================================================
Edit: 27.05.11
Name Size Bytes Class Attributes
C 997x997 131209188 cell
B 2991x2991 71568648 single complex
Bdp 2991x2991 143137296 double complex
Bsparse 2991x2991 156948988 double sparse, complex
Bdp=double(B);
Bsparse=sparse(Bdp);
I used single precision, witch gave the same accuracy as in double precision
It's better, Am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些建议:
Ax=b
),则应使用 MATLAB 的 反斜杠运算符。A few suggestions:
Ax=b
), you should use MATLAB's backslash operator.当您拥有的每个矩阵本身就有 600 MB 时,3GB 并不算多。如果您无法更改算法,则需要在 64 位操作系统上运行 64 位 matlab,并具有更多 RAM。这是获得大量内存的唯一方法。请注意,对于 3 GB,Matlab 只有 2.2 GB,最大的块是 1.5 GB - 这只是您的矩阵的 2 个。
3GB isn't alot when each matrix you have is 600 MB all by it's self. If you can't make the algorithmic changes, you need 64-bit matlab on a 64-bit OS, with alot more RAM. It's the only way to get alot of memory. Notice that with 3 GB, Matlab only has 2.2 GB, and the largest chunk is 1.5 GB - that's only 2 of your matricies.
Matlab 有一种简单的方法来处理像 1000000*1000000 这样的巨大订单矩阵。
这些矩阵通常是稀疏矩阵,不需要为零值的矩阵元素分配 RAM 内存。
所以你应该使用这个命令:
A=sparse(1000000,1000000); “定义一个 1000000 x 1000000 的零矩阵。”
然后您可以通过“spdiags”等命令设置对角线非零元素。
请参阅此链接: http://www.mathworks.nl/help/matlab/ref /spdiags.html
请注意,您不能使用“inv”命令来反转矩阵 A,因为“inv”创建了一个普通矩阵并使用了大量 RAM 空间。(可能会出现“内存不足”错误)
到求解 A*X=B 等方程,可以使用 X=A\B。
Matlab has an easy way to handling huge matrices of orders like 1000000*1000000.
These matrices are usually sparse matrices and it's not necessary to allocate RAM memory for matrix elements of zero value.
So you should just use this command:
A=sparse(1000000,1000000); "Defining a 1000000 by 1000000 matrix of zeroes."
Then you can set the diagonal nonzero elements by commands like "spdiags".
See this Link : http://www.mathworks.nl/help/matlab/ref/spdiags.html
Note that you can not use "inv" command to invert matrix A, because "inv" made a normal matrix and uses a lot of space of the RAM.(probably with "out of memory" error)
To solve an equation like A*X=B, you can use X=A\B.