Memory during a loop
Afficher commentaires plus anciens
Hi,
If I run Clear All during a loop, will it also clear the loop value?
Thanks,
1 commentaire
Aadil
le 6 Sep 2012
Réponse acceptée
Plus de réponses (2)
Arthur
le 6 Sep 2012
sure, you can just clear the variable:
clear varname
check:
doc clear
3 commentaires
Aadil
le 6 Sep 2012
Arthur
le 6 Sep 2012
Do you need to load all the variables at once? You can also load a single variable at the time.
S = load(filename, variables)
This can be more memory efficient, but you may have to open the file multiple times...
Jan
le 6 Sep 2012
+1. Especially the suggested "S=load()" is a very good idea.
Sean de Wolski
le 6 Sep 2012
Modifié(e) : Sean de Wolski
le 6 Sep 2012
It depends on where you call it, compare:
- 1
for ii = 1:10
ii
clear all
end
- 2
for ii = 1:10
clear all
ii
end
But of course Arthur is right - you shouldn't need to use clear all at all.
2 commentaires
Aadil
le 6 Sep 2012
Sean de Wolski
le 6 Sep 2012
Assign the *.MAT file you load to a variable then clear it when you're done. That way you aren't poofing variables into your workspace.
for ii = stuff
S = load('mymatfile.mat');
do_stuff_with(S)
clear S
end
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!