hello
i have a text file with name of bp. u see many 'TSTEP' in this file. there are other written text just below them like: '1*100'. now i want to find these 'TSTEP's and make changes on the text below them (just changing the number before the asterisk). for example '1*100' is going to be '2.5*100' or any other number can be replaced. i use this code when i have one 'TSTEP' in file. ut it doesnt work for the cases when there are more than one of it. the number of TSTEPs may differ from file to file. is it possible to do that?
thanks in advance
clc;fid=fopen('bp.txt','r');c=textscan(fid,'%s','delimiter','\n','Whitespace','','CommentStyle','1','CollectOutput',0);fclose(fid);c=string(c{:})iz=find(contains(c,"TSTEP"));d1=['2.5','*',extractAfter(c{iz+1},'*')];d2=replace(c,c{iz+1},d1);fid = fopen('bp.txt','w');for j= 1:length(d2) fprintf(fid, '%s\n', char(d2{j}));endfclose(fid);
Best Answer