I have a txt file which has the following content in the middle of the text:
set TC_SYS_01 0set TC_SYS_02 0...set TC_SYS_38 0
Now if input is 10,the first 10 lines value has to be set to 1. example:=
set TC_SYS_01 1...set TC_SYS_10 1
———————————– Updated Code——————————
% if input says 10
content = fileread('run.txt');newcontent = regexprep(content, '(?<=set TC_SYS_\d*\s+)[01]','0');% the above line is just to make sure all of them are 0,if any of them are 1;
fid = fopen('run.txt','w');fwrite(fid,newcontent);fclose(fid);% now all lines are value is 0.
% Variable is 10,so first 10 to be set to 1
content = fileread('run.txt');%%%%%%%%%%%%%%%%%
newcontent = regexprep(content, '(?<=set TC_SYS_[0]\d\s+)[01]','1'); %this line
%%%%%%%%%%%%%%%%%fid = fopen('run.txt','w');fwrite(fid,newcontent);fclose(fid);
how to write the line with comment 'this line' so that i can directly write the variable into expression instead of hard coding as i have done in the above code ?
This question is in some ways related to my previous question: http://in.mathworks.com/matlabcentral/answers/248317-change-the-content-in-an-m-file-based-on-check-box-input-from-gui
Best Answer