2015-10-19 38 views
2

是否有任何MATLAB命令讓我們在由於大量數據導致90%的RAM已滿時終止MATLAB代碼?當RAM滿時終止MATLAB代碼

我在問這個問題,因爲我不想在MATLAB每次卡住並且計算機被掛起時重新啓動計算機?

+0

是的,看看這個:http://uk.mathworks.com/matlabcentral/answers/59491-is-it-possible-to-set-watchdogs-memory-exec-time-in-matlab – GameOfThrows

+0

@GameOfThrows Add就像在這裏一樣,因爲它在SO中很有用! –

回答

2

據我所知,你不能「自動」這樣做,如果MATLAB掛起,它會掛起。

但是,在您的代碼中,您可以隨時添加某處(例如在內存繁重的迭代函數中)進行內存檢查。

如果你

maxmem=2e10; %about 2GB of RAM 

%% //this inside the memory heavy code 
mem=memory; 
if mem.MemUsedMATLAB>maxmem 
    exit; % // or some other thing you may want to do 
end 

這將退出MATLAB時的內存約爲2GB的RAM(該值在位,所以一定要注意,讓自己的值時)

2

添加這個答案,因此,通過@Ander Biguri,答案的建議如果單純基於this link

利用Matlab嘗試(作爲一個選項),可以監視內存的使用情況作爲

tryOptions.watchdog.virtualAddressSpace = 7e9 ; %//7GB Mem 
tryOptions.watchdog.execTime = 1800 ;   %//Execution Time 1800 seconds 
try tryOptions 
... 
catch %// use the try and catch combo to monitor your memory usage and kill process if you need to. 

其他有用的工具,它可以幫助:

T = evalc('feature(''memstats'')') ; 
str2mat(regexp(T, '(?<=Use:\s*)\d+', 'match')) 

的memstats可以輸出你的內存的當前統計數據,你可以在你的代碼添加斷點(在大手術的開始)來監控您的內存使用情況並決定是否要繼續執行。

+0

這個(答案的第一部分)是否真的有效?我更多地將這個鏈接解釋爲一個功能請求。 – hbaderts