在文本文件中找到关键字,然后选择旁边的值

时间:2018-06-25 23:57:09

标签: matlab parsing

我有一个很大的非同质文本文件。我需要在文本中找到关键字,然后选择关键字旁边的值。这是此文本文件的一部分:

  LAW NUMBER ............... =    45.54553
  LAW TYPE:
  152
   Geomaterial_2 - solid PHASE                                
  ELASTIC CONSTITUTIVE LAW FOR SOLID ELEMENTS
  AT CONSTANT TEMPERATURE
  USE OF EFFECTIVE STRESSES. ISOL =    1
  NUMBER OF SUBINTERVALS.... NINTV=    1
  YOUNG'S MODULUS .......... =   0.200000E+08
  POISSON'S RATIO .......... =   0.300000    
  SPECIFIC MASS AS A MATERIAL LAW,
  RHO ...................... =    2670.00    
  LAW TYPE: 
  171
   Geomaterial_2 - liquid PHASE                               
  WATER-AIR SEEPAGE- VAPOR -THERMAL COUPLED
  CONSTITUTIVE LAW FOR SOLID ELEMENTS
  ISOTROPIC CASE IANI =     0
  FORMULATION INDEX FOR krw IKW  =     0
  FORMULATION INDEX FOR kra IKA  =     0

我需要带十进制值的'LAW NUMBER'的完整值,如果'LAW NUMBER'的值为负,则类似。我该怎么办?

我有以下脚本:

% Import the whole file at once

fid  = fopen('test.txt','r');
text = textscan(fid,'%s','Delimiter','');
text = text{1};
fid  = fclose(fid);
% Parse LAW NUMBER

LW = regexp(text,'LAW NUMBER[\s\.=]+(\d+)','tokens');
LW = [LW{:}];
LW = str2double([LW{:}]).';
% Parse LAW TYPE

0 个答案:

没有答案