Given
- the entire file fits in a fraction of the memory
- *END* is the last line before the numerical part of the file. (This is the only occurrence of *END*.)
- all files have 29 columns of numerical data
then one way is
str = fileread( 'd94i006.txt' );
str = regexp( str, '(?<=\*END\*\s+).+$', 'match' );
cac = textscan( str{1}, repmat('%f',[1,29]), 'CollectOutput',true );
num = cac{1};
result
>> whos num
Name Size Bytes Class Attributes
num 339x29 78648 double
Note: "has about 130 header lines." makes it safer to use the line *END*.
In response to comment "loop [...] every file from the folder?"
Try
>> cac = cssm( 'c:\your_folder\with_data\' );
where in one file
function cac = cssm( folderspec )
sas = dir( fullfile( folderspec, '*.txt' ) );
len = length( sas );
cac = cell( 1, len );
for jj = 1 : len
cac{jj} = cssm_( fullfile( folderspec, sas(jj).name ) );
end
end
function num = cssm_( filespec )
str = fileread( filespec );
str = regexp( str, '(?<=\*END\*\s+).+$', 'match' );
cac = textscan( str{1}, repmat('%f',[1,29]), 'CollectOutput',true );
num = cac{1};
end
As is; Not tested Needed: better names and some comments. There is a magic number, 29, in the code.
Best Answer
This is one way to read the your file
where (in one m-file)
 
Comments:
The function is slow. Nearly all the time is spend with regexp searching for "Num of cells" and "Porosity". "the Num of cells and porosity value are the same." may be used improve speed. Adding 'once' to these two calls of regexp increases the speed forty times. That's much more than I anticipated; I don't understand; I cannot see what's taking all the extra time.