<div>Hi Virginie,</div>
<div> </div>
<div>There are a couple of other things you can do.</div>
<div> </div>
<div>First, make certain that you are not growing any variables inside a loop. For example, if you have any code like:</div>
<div> </div>
<div>for i=1:size(data,1)</div>
<div>for j=1:size(data,2)</div>
<div>newvar(i,j)=data(i,j); </div>
<div>end</div>
<div>end</div>
<div> </div>
<div>make sure that you precede this code with:</div>
<div> </div>
<div>newvar=zeros(size(data));</div>
<div> </div>
<div>This will not only speed up the execution of your code but can prevent memory errors in matlab.</div>
<div> </div>
<div>Second, use the clear function to remove any variables that are no longer necessary.</div>
<div> </div>
<div>Third, type 'pack' at the command line prior to executing the part of your code that generates the memory error.</div>
<div> </div>
<div>If none of this works, there are two more options that I'm aware of for avoiding a memory error.</div>
<div> </div>
<div>First, you can run your analysis on a computer with a 64-bit architecture and a 64-bit operating system. The reason that you are still encountering memory errors despite having virtual memory maximized is that 32-bit systems are incapable of addressing more than approximately 4 GB of memory, regardless of how much is available. This limitation is effectively removed on 64 bit systems (or rather, the limitation is several orders of magnitude higher).
</div>
<div> </div>
<div>Finally, you can run your analysis in steps, saving the results of each step and clearing all the data. I've certainly had to do this before when working in fieldtrip. For example, if you're attempting to timelock analyses, load each subject individually and grandaverage their trials, saving the results to a new variable. Then clear their data, load the next subject, and continue. In addition, with the datasets I've used in FIELDTRIP I've noticed that for most functions specifying
cfg.keeptrials='yes' is likely to generate memory errors, and for frequency analyses specifying cfg.parameter='powandcsd' and using a large number of pairings in cfg.channelcmb (or leaving it at default) is pretty well guarenteed to generate a memory error.
</div>
<div> </div>
<div>Good luck!</div>
<div> </div>
<div>-Jared<br><br> </div>
<div><span class="gmail_quote">On 6/28/07, <b class="gmail_sendername">Virginie van Wassenhove</b> <<a href="mailto:vvw@caltech.edu">vvw@caltech.edu</a>> wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi fieldtrippers,<br><br>would anyone have a trick to share for optimizing memory in matlab...?<br><br>What I have tried so far (insufficient still):
<br>- let windows manage memory<br>- boost virtual memory to maximum (on 2 drives!)<br>- clear all unnecessary variables in mat space<br>- disable java<br>- turned off graphic hardware acceleration<br>- shut off unused processes
<br><br>I am running out of options...Would using a mac solve these issues?<br><br>Thanks in advance,<br>-vv<br><br><br>Virginie van Wassenhove, PhD<br><br>:::::::::::: contact info  :::::::::::::<br>Caltech - Division of Biology
<br>1200 E. California Blvd M/C 139-74<br>Pasadena CA 91125 USA<br>:::::::::::::::::::::::::::::::::::::::::::::::::<br><a href="mailto:vvw@caltech.edu">vvw@caltech.edu</a><br><a href="mailto:Virginie.van.Wassenhove@gmail.com">
Virginie.van.Wassenhove@gmail.com</a><br>W: 626.395.8959<br><a href="http://www.its.caltech.edu/~vvw">http://www.its.caltech.edu/~vvw</a><br><br>:::::::::::::::::: extras ::::::::::::::::::::<br><a href="http://www.kiva.org">
http://www.kiva.org</a><br><a href="http://www.thehungersite.com/">http://www.thehungersite.com/</a><br><a href="http://www.agloco.com/r/BBBS1539">http://www.agloco.com/r/BBBS1539</a><br>:::::::::::::::::::::::::::::::::::::::::::::::::
<br><br>----------------------------------<br>The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis. See also
<a href="http://listserv.surfnet.nl/archives/fieldtrip.html">http://listserv.surfnet.nl/archives/fieldtrip.html</a> and <a href="http://www.ru.nl/fcdonders/fieldtrip">http://www.ru.nl/fcdonders/fieldtrip</a>.<br></blockquote>
</div><br><br clear="all"><br>-- <br>Jared Van Snellenberg<br>Social Cognitive Affective Neuroscience Unit<br><a href="http://scan.psych.columbia.edu">http://scan.psych.columbia.edu</a><br>(212) 854-7858 p<br>(212) 854-3609 f
<br>Department of Psychology, Columbia University<br>406 Schermerhorn Hall<br>1190 Amsterdam Avenue, Mail Code 5501<br>New York, NY 10027<br>_______________________________<br>"Luck is the residue of design"<br>
-Attributed to Branch Rickey, former US Baseball Administrator, and also to John Milton. Go figure.
<p>----------------------------------</p>
<p>The aim of this list is to facilitate the discussion between users of the FieldTrip  toolbox, to share experiences and to discuss new ideas for MEG and EEG analysis.</p>
<p>  http://listserv.surfnet.nl/archives/fieldtrip.html</p>
<p>  http://www.ru.nl/fcdonders/fieldtrip/</p>