RAM crash because of multiple looping, how to solve the problem?

1 次查看(过去 30 天)
l = find(lamda >= fmin & lamda <= fmax);
lam = lamda(l);
n = length(lam);
C = zeros(n,n,n,n,n);
C = zeros(n,n,n,n,n) + inf;
for i = 1:n
for ii = 1:i-1
for iii = 1:ii-1
for iv = 1:iii-1
for v = 1:iv-1
A = data(l([i ii iii iv iv]), 1:3);
C(i,ii,iii, iv, v) = cond(A);
vif(i,ii,iii,iv,v) = max(diag(inv(A'*A)));
end
end
end
end
end
  1 个评论
Kirby Fears
Kirby Fears 2015-12-17
编辑:Kirby Fears 2015-12-17
Muhannad,
It looks like you are initializing C twice but not initializing vif at all.
C = zeros(n,n,n,n,n);
C = zeros(n,n,n,n,n) + inf;
You should initialize vif also:
C = zeros(n,n,n,n,n); % add Inf here if you want
vif = zeros(n,n,n,n,n);
This will pre-allocate memory for vif as well, which will help the speed of your run.
These initialization steps are going to cause a RAM crash if n is too large. For example, if n is 100, C and vif will each have 100^5 = 10 billion elements.
The loops themselves are not crashing your RAM. The size of C and vif (based on n) are the problem.

请先登录,再进行评论。

回答(1 个)

Krishnan Ramkumar
Krishnan Ramkumar 2015-12-17
Hi Muhannad,
Can you please tell me the problem that you would like to solve so that we can see if there is any optimized way to resolve the issue . For large values of n, it is expected to use high memory usage and also depends on the number of applications that are used at that point of time. Also can you tell me the system configuration that you are using?
Regards,
Krishnan

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by