I am writing a Matlab program that reads about 500 files. Each file has 20,000 lines with 1 number on each line. The program is trying to build a matrix of size 20,000 * 500 with these numbers. The numbers are stored as Binary, so 8 bytes per number. Therefore, I expect this to take 20,000 * 500 * 8 bytes, which is roughly equal to 1E8, i.e. 100 MB. And yet this program runs out of my 16 GB memory. As the program starts, I see that memory usage is steadily increasing, GB GB. I am using Matlab R2015b on Ubuntu 14.04.
What's happening? Thank you very much for your attention.
Here is the complete code
clear all; % number of rna bits in the file filesize = 20532 maxFiles = 480; rnaCounts = NaN(filesize,maxFiles); myFolder = '~/_STATS/data3/RNASeqV2/UNC__IlluminaHiSeq_RNASeqV2/Level_3'; filePattern = fullfile(myFolder, '*genes.normalized_results'); theFiles = dir(filePattern); rnaCounts = NaN(filesize,length(theFiles)); for k = 1 : length(theFiles) mrnaFilename = strtrim(theFiles(k).name); fprintf(1, 'Now reading mrnaFile %d %s \n', k, mrnaFilename); % read rna file fullFileName = fullfile(myFolder, mrnaFilename); rnafid = fopen(fullFileName); if rnafid < 0 fprintf('====ERROR OPENING RNA FILE ====================='); end rnaline = fgets(rnafid); lc = 1; % line counter while ischar(rnaline) && feof(rnafid) ~= 1 rnaline = fgets(rnafid); rnaSplit = strsplit(rnaline); % write to the matrix rnaCounts(lc,k) = str2num(rnaSplit{2}); lc = lc + 1; end fclose(rnafid); end
source share