Fastest way to create arrays programmatically for particular parameter values from a set of text files

2 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Walter Roberson
Walter Roberson am 9 Jul. 2019
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 Kommentare
Wander11
Wander11 am 9 Jul. 2019
I was not exactly looking for the grep functionality. I have reworded the question.
Walter Roberson
Walter Roberson am 9 Jul. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by