RAM crash because of multiple looping, how to solve the problem?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Kirby Fears
il 17 Dic 2015
Modificato: Kirby Fears
il 17 Dic 2015
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.
Risposte (1)
Krishnan Ramkumar
il 17 Dic 2015
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
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!