Fastest way to create arrays programmatically for particular parameter values from a set of text files
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a collection of folders at location say 'folderpath'. Inside , each of this, I have a txt file myfile.txt. There are 4 parameters in this file "type 0, val1" ,"type 0, val2" , "type 1, val1" and "type 2, val2" .The formatting is exactly as indicated. Note that there are multiple instances of these 4 parameters inside the text file.
My aim is to create 4 arrays , one for each parameter. There are around 200,000 instances of each parameter in the txt file. So I need four arrays of 20,000 size. And I have around 100 folders each of which has such a txt file.
What is the fastest way of achieving this in MATLAB.
I used
content = fileread( 'myfile.txt' ) ;
numbers = str2double(regexp(content, '(?<=Rank 1,val1[^0-9]*)[0-9]*\.?[0-9]+', 'match'))
But it is taking too long.
I am attaching a sample txt file.
댓글 수: 0
답변 (1개)
Walter Roberson
2019년 7월 9일
The fastest way of grepping is MATLAB is to system() out to a Unix grep or egrep utility.
The second fastest way is to invoke perl from MATLAB to do the matching for you.
댓글 수: 2
Walter Roberson
2019년 7월 9일
The method in MATLAB that is the most efficient for elapsed time and CPU time, is to system() out to a grep or egrep utility. The method that is the most efficient for time spent writing the code is to use the code that you already have, since you already have it.
You have repeatedly emphasized the fastest way, and these are the fastest ways. egrep executables are much more efficient than MATLAB is.
If you wish to confine your implementation to MATLAB without external utilities then Yes, there are ways that are probably more efficient than what you are doing already, but they would not be the fastest that you could do using MATLAB without such a restriction.
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!