如何在 MATLAB 中从大型文本文件的重复格式读取数据?
我想读取水的平均饱和度(%)数据,如下所示。该数据是大文件的部分形式,但是平均水饱和度 (%) 仅以给定格式重复。
Average Pressure
Total Pore Volume psia 3884.9
HC. Pore Volume psia 3884.9
Average P/Z
Total Pore Volume psia 4457.8
HC. Pore Volume psia 4457.8
Average Saturation %
Oil 84.911
Gas .08873
Water 15.000
Percentage Recovery
Stock Tank Oil .02211
STO as a % of Mobile Oil .02891
Total Gas .02034
Water 62e-12
我试图通过使用 readline 来做到这一点。 m 函数,但不幸的是平均含水饱和度(%)数据的位置不是由行号固定的。不同型号的类似输出文件的行号会发生变化。
这就是我想要做的:
%# Reading Water Saturation (Sw) data from output (.OUT) file of reservoir model
Sw_LineNo=[554,968,1120,1272,1424,1576,1728,1880,2032,2184,2336,2488,2640,2792,2944,3096,3248,3400,3552,3704,3856]; % This column vector contains the line numbers of the .out file with Sw values for year 1 till 20
for i=1:size(Sw_LineNo,2)
read_value=readline('ReservoirModel_ExplorWell_CMGBuilder.out',Sw_LineNo(i)); % read_value stores values in form of string
Swav_Data_E_W(i,j)=str2num(read_value(33:38)); % converts the required portion of string (Sw value) to number
end
现在,如果我的模型 (ReservoirModel_ExplorWell_CMGBuilder.out
) 发生变化,那么文本文件中水的平均饱和度 (%) 所在的行号也会发生变化。因此 Sw_LineNo
会根据不同的模型而变化,并且我有大量模型。
请建议读取水数据的所有平均饱和度 (%) 的正确方法。
I want to read data of average saturation (%) for water as shown below. This data is a partial form of a large file, however the average water saturation (%) REPEATS itself in the given format only.
Average Pressure
Total Pore Volume psia 3884.9
HC. Pore Volume psia 3884.9
Average P/Z
Total Pore Volume psia 4457.8
HC. Pore Volume psia 4457.8
Average Saturation %
Oil 84.911
Gas .08873
Water 15.000
Percentage Recovery
Stock Tank Oil .02211
STO as a % of Mobile Oil .02891
Total Gas .02034
Water 62e-12
I was trying to do it by using readline.m function, but unfortunately the position of average water saturation (%) data is not fixed by line number. The line number changes for similar kind of output file for different models.
This is what I was trying to do:
%# Reading Water Saturation (Sw) data from output (.OUT) file of reservoir model
Sw_LineNo=[554,968,1120,1272,1424,1576,1728,1880,2032,2184,2336,2488,2640,2792,2944,3096,3248,3400,3552,3704,3856]; % This column vector contains the line numbers of the .out file with Sw values for year 1 till 20
for i=1:size(Sw_LineNo,2)
read_value=readline('ReservoirModel_ExplorWell_CMGBuilder.out',Sw_LineNo(i)); % read_value stores values in form of string
Swav_Data_E_W(i,j)=str2num(read_value(33:38)); % converts the required portion of string (Sw value) to number
end
Now if my model (ReservoirModel_ExplorWell_CMGBuilder.out
) changes, then the line numbers where the average saturation (%) for water lies in the text file also changes. Thus Sw_LineNo
changes for different models, and I have large number of models.
Please suggest correct way to read all the average saturation (%) for water data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在 tmp_str = dotOUT_fileContents(Swav_Starts(w)+3); 生成以下字符串:
如果我尝试使用 str2num 将其转换为数字,则会得到一个空矩阵。因此,我选择包含饱和度值的字符串字符(此处为
15.000
),然后将此字符更改为数字,如下所示,给出平均水饱和度的值:如果有人有任何方法,请告知从字符串中提取数字,而不像我那样选择字符。
Now the
tmp_str = dotOUT_fileContents(Swav_Starts(w)+3);
produces the following string:If I try to convert it to number using str2num, then I get an empty matrix. So I pick the characters of this string containing the saturation value (here
15.000
) and then changing this character to number as follow, giving the value of the average water saturation:Please advice if someone has any method to extract number out of the string without picking the characters as I have done.