how can i edit this data file using MATLAB?

조회 수: 11 (최근 30일)
Ulduz
Ulduz 2018년 4월 15일
편집: Ulduz 2018년 4월 16일
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