%do not overwrite the old file; we are counting on the old field being 15.0000
filename = fullfile('D:\','app','try1','TRY1B','w2_con.npt ');
newfile = fullfile('D:\','app','try1','TRY1B','new_w2_con.npt ');
S = regexp( fileread(filename), '\n', 'split');
newval = 6;
S{48} = regexprep(S{48}, '15\.0000', sprintf('%.4f', newval), 'once');
S = strjoin(S, '\n');
[fid, msg] = fopen(newfile, 'w'); %not 'wt'
if fid < 0
error('Failed to open file "%s" for writing because "%s"', newfile, msg);
end
fwrite(fid, S);
fclose(fid);
If you cannot count on the field to replace being a specific value, then you may have to replace by position, which can be a bit tricky as it looks like you might possibly be using fixed width fields (or possibly they are tab separated.)
Your existing code to read the fields is not going to do well on lines such as
WB 1 ET OFF OFF ON OFF 15.0000 2.00000 2.00000 10.0000
as the character fields are permitted to have embedded blanks which you are reading in as separate fields.
