- Is   cutTDM400_111_111_000_000_000   a sample name?
- Does   [1;33m--- Initializing LBM Domain   indicate the beginning of a "cell" ?
- I would use fileread and regexp
Extracting information from file
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Julia
el 8 de Mzo. de 2016
Editada: per isakson
el 8 de Mzo. de 2016
I am trying to extract information from the attached file and write them into a matrix with one column each from sample name, number of cells and porosity. I have been trying textscan and sscanf, but am not sure how to search the structure of the text.
3 comentarios
per isakson
el 8 de Mzo. de 2016
Editada: per isakson
el 8 de Mzo. de 2016
Now, I think I understand. The word "cells" in "Num of cells" has nothing to do with the word "cell" in "beginning of a cell is indicated".
First, I thought you wanted to count some kind of "sections" of the file. I missed "Num of cells = 32000000" when I first browsed the file.
Respuesta aceptada
per isakson
el 8 de Mzo. de 2016
Editada: per isakson
el 8 de Mzo. de 2016
This is one way to read the your file
>> tic, sas = nohup, toc sas = 1x1173 struct array with fields: SampleName NumOfCells Porosity Elapsed time is 27.000338 seconds. >> ix = find( strcmp( {sas.SampleName}, 'cutTDM050_111_121_221_222_122' ) ) ix = 583 >> sas(ix).Porosity ans = 0.0828 0.0828 0.0828 >> sas(ix).NumOfCells ans = 125000 125000 125000
where (in one m-file)
function sas = nohup %% str = fileread( 'nohup.txt' ); %% heading_string = 'Running Sample'; trailing_string = '=============================================='; % xpr = sprintf( '(?<=%s).+?(?=%s)', heading_string, trailing_string ); cac = regexp( str, xpr, 'match' ); %% sas = struct( 'SampleName',repmat({''},[1,length(cac)]) ... , 'NumOfCells',{[]}, 'Porosity', {[]} ); for jj = 1 : length( cac ) sas(jj) = nohup_( cac{jj} ); end end function sas = nohup_( str ) % sas.SampleName ... = regexp( str, 'cutTDM\d{3}_\d{3}_\d{3}_\d{3}_\d{3}_\d{3}', 'match', 'once' ); % cac = regexp( str, '(?<=Num of cells +\= *)\d+', 'match' ); sas.NumOfCells = str2double( cac ); % cac = regexp( str, '(?<=Porosity +\= *)[\d+\.]+', 'match' ); sas.Porosity = str2double( cac ); end
 
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.
>> tic, sas = nohup, toc sas = 1x1173 struct array with fields: SampleName NumOfCells Porosity Elapsed time is 0.645206 seconds. >> ix = find( strcmp( {sas.SampleName}, 'cutTDM050_111_121_221_222_122' ) ) ix = 583 >> sas(ix).Porosity ans = 0.0828 >> sas(ix).NumOfCells ans = 125000 >>
Más respuestas (0)
Ver también
Categorías
Más información sobre Low-Level File I/O en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!