我用这个程序来读一个包含字符的数据文件,然后锁定特定字符所在的行数,来读取特定字符下面的数据,这个是我的程序:
lineNum=0;line=[];
fid=fopen('PROCAR.txt');
fidout=fopen('PROCAR.txt','w');
atoms=6;
i=2;
nline = 0;
while ~feof(fid)
lineNum=lineNum+1;
tline = fgetl(fid);% read the text file by rows
if strncmpi(tline,'band 1 #',10)==1
line=[line;lineNum];
a1=line+(atoms+1)+2+i;
a2=line+(atoms+1)2+2+i;
a3=line+(atoms+1)3+2+i;
end
if ~ischar(tline), break, end
nline = nline + 1;
if nline == line+(atoms+1)+2+i % ensure the correct rows can be find and extract
geo = tline;
end
if nline == line+(atoms+1)+2+i
tex = tline;
end
end
geo_valuses = regexp(geo,'\d.?\d','match');% extract numbers in string 正则表达式
b=str2num(geo)
由于有900个相同的字符所以就可以读出这900个相同字符所在的行数,也就有900行,那么根据字符读取下面的数据也就有900个行数,我现在不知道怎样一次性把这900行里面的数据一次性都输出来,请教一下各位。