how can i edit this data file using MATLAB?

11 次查看(过去 30 天)
Hello This is my data file. Its name is “FAR.DATA”(here it is saved in txt file). I want MATLAB to read its content and find some keywords in it so I Edit the data related to that keyword (the data of each keyword is placed under that keyword till the slash sign). This is the mat code I used to find keywords WELSPECS and COMPDAT. The data file which is in a notepad file is defined as struct. The code could find the line number of each keyword, but unable to find the number of lines between the asked keyword and its backslash sign. Could someone help me with that? file format is .DATA but this format is unsupported here so i have changed it to .txt. thanks

回答(1 个)

Ulduz
Ulduz 2018-4-15
编辑:Ulduz 2018-4-15
clc;
fid = fopen('FAR.DATA','r');
model.datafile = textscan(fid, '%s','Delimiter','');
fclose(fid);
model.datafile = model.datafile{:};
DATA = model.datafile;
% Find COMPDAT line
La = ~ cellfun(@isempty, strfind(DATA,'WELSPECS','ForceCelloutput',true));
Lia = ~ cellfun(@isempty, strfind(DATA,'COMPDAT','ForceCelloutput',true));
Welspecs = model.WELSPECS; %%The Number of WELSPECS and COMPDAT and WCONPROD
in which the parameters are changed.* _
Compdat = model.COMPDAT;
mm = model.CompletionNodes;
LNCOMPDAT=find(Lia); % Line number of COMPDAT
LNWELSPECS=find(La); % Line number of WELSPECS
% Next line after COMPDAT is Well Completion DATA — LN+1 % Spliting The line of Data for ii = 1:size(Welspecs,1) % In this loop the line of WELSPECS and COMPDAT is conveted to cell array
for jj =1:Welspecs(ii,2)
splitSt{jj,ii} = regexp(cell2mat(DATA(LNWELSPECS(Welspecs(ii,1))+jj)),'\ ','split');
end
for jj=1:Compdat(ii,2)
splitStr{jj,ii} = regexp(cell2mat(DATA(LNCOMPDAT(Compdat(ii,1))+jj)),'\ ','split');
end
end

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by