high physicial memory usage
조회 수: 1 (최근 30일)
이전 댓글 표시
hello, I'm working with a script that does the folowing: 1. load a file (high reslolution audio file: 5 seconds long about 2.5mb) 2. run a apectrogram on the audio file 3. save the figure as a jpeg 4. repeat 1440 times. when i'm running the script, the physical memory that matlab is using keeps getting higher and higher untill it reaches 100% (about 35gb) and stops (crashes). my question is, why would the memory usage keep rising? and are there ways to fix this problme?
댓글 수: 3
채택된 답변
Guillaume
2018년 4월 3일
Each time you call spectrofun2 you create a new figure. You never close the figure, so if you're processing 1400 files, you'll end up with 1400 open figures. You can't see these figures since you've set their visibility to off. That's also why clear did not have any effect. close all would have had.
The fix is simple add
close(figure1)
as the last line of spectrofun2 (before the end obviously).
------
Unrelated, if you're on R2016b or later, your code can be greatly simplified as dir lets you obtain all the files in subfolders directly.
filelist = dir(*/*.mat); %requires R2016b or later
would get all the mat files in the subfolders of the curent folder.
------
Also unrelated,
fullList(1:2)=[]; %detele first 2 '.','..'
is not a safe way of getting rid of '.' and '..' as there's no guarantee that these two will be the first two directories returned by dir (They won't be if another directory starts with any of !"#$%&'()*+,-). This is guaranteed to work:
fullList(ismember({fullList.name}, {'.', '..'})) = [];
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!