Caught std::exception Exception message is: bad allocation
조회 수: 10 (최근 30일)
이전 댓글 표시
Hi to all!
I am trying to run the code below as suggested by Andrei in this forum to get a data set converted into a 633 by 150005 Matlab matrix for further analysis. The data file itself consists of 633 lines with at most 150005 characters per line plus 1897 headerlines on top of it.
fid = fopen('datafile.txt');
t = textscan(fid,'%150005c','HeaderLines',1897,'BufSize',160000);
fclose(fid);
out = reshape(regexprep(t{1}(:)',{'o',' ','"',','},{'1' '0' 'b' 'e'}),size(t{1}))-'0';
Experiments with 2 lines of 150005 characters yielded a correct 2 by 150005 Matlab variable, at least by changing the BufSize to 160000. However, when I try to run the scripts above using my "real data", it gave the following message and no result at all.
Caught std::exception Exception message is: bad allocation
By typing in memory at the prompt, I get what follows. This may be helpful in resolving the issue.
Maximum possible array: 223 MB (2.340e+008 bytes) *
Memory available for all arrays: 775 MB (8.129e+008 bytes) **
Memory used by MATLAB: 1028 MB (1.078e+009 bytes)
Physical Memory (RAM): 2031 MB (2.129e+009 bytes)
* Limited by contiguous virtual address space available.
** Limited by virtual address space available.
I attempted pre-allocating by creating zeros(633,150005) but I get "Out of memory. Type HELP MEMORY for your options." Please help.
Thanks,
Bernard
댓글 수: 2
Walter Roberson
2012년 2월 13일
http://www.mathworks.com/matlabcentral/answers/28742-converting-a-text-file-to-a-matlab-matrix-variable
답변 (1개)
Walter Roberson
2012년 2월 13일
Read a line at a time and covert it and store it. The arrangement you have now requires two copies in memory at the same time (original and translated), and that would go through your memory limit even if you were not using 8 bytes per character in the translated output.
As you only have 4 distinct values (it appears from the above), you should store the results as uint8 to save memory.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!