quit doesn't quit the matlab when called from a loop.
显示 更早的评论
Hello,
I am running a m-script that makes a lot of memory leak, and it reaches 2GB in about 3 hours. Since I am calling a lot of functions that somebody else created, I figured it is easier to just restart the function whenever it reaches memory maximum, and resume the loop. So, I implemented [!matlab -r myMscript] in the loop, but it won't quit so it won't free up the memory.
For example, the following script doesn't quit the matlab.
for i = 1:100,
if mod(i,20)==0,
!matlab -r test=1
quit
end
end
My matlab version is 7.7.0.471, and I have 64bit computer (Windows 7). The matlab is running with 32bit-mode.
Could anybody help me to dissovle this problem?
Best,
Ji Hyun
采纳的回答
更多回答(2 个)
Sean de Wolski
2012-3-7
Interesting idea. when you run:
!matlab
it halts execution in the current MATLAB instance until the new instance closes.
Daniel Shub
2012-3-7
0 个投票
I think Sean de gives the reason for your problem. As for a work around, I can think of a bunch of ways and it is really what you are most comfortable with. I think the key is to modify your script/function so that it only does a few loops and then exits. The "hard" part is letting the script figure out what loops to do. You could use the script name, check for an environment variable, pass an argument, etc).
Then you need to call the script/function, wait for it to end, and call the next one. If you have the parallel computing toolbox and/or a cluster, you could use a scheduler. I would probably write a shell script to do it. You could use MATLAB to do it.
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!