how to amend an existing text file in a certain line and create new ones
이전 댓글 표시
Hello all
I've got a text file and I need to change only one parameter of it many times (in a for loop).
Until now, I've located the line where my parameter is, I've changed it and NOW I NEED TO WRITE THE NEW PARAMETER IN A NEW TEXT FILE, WHOSE ONLY DIFFERENCE WITH THE PREVIOUS ONE WOULD BE THE DIFFERNT PARAMETER VALUES.
My code until now looks like that.
%Define the range of the parameter sathh
%Assume that sathh can vary between 0.01 and 0.05
parameterA_range = 0.01:0.01:0.05;
%The loop counter
for i=1:length(parameterA_range)
%Extract each value from the range of the parameterA_range
param1 = parameterA_range(i)
%Replicate each of these values 4 times (4 soil layers) and create the new
%parameter set
parameterA = repmat(param1,1,4)
%Replace the parameterA with the new parameterA parameters.
%Open the txt file and scan through it
fid = fopen('sensanalysis3.txt');
C = textscan(fid,'%s','delimiter','\n');
%Find the line number 188, where the parameterA is
line188 = C{1}{188}
line188_changed =strrep(line188,'0.0453, 0.0453, 0.0453, 0.0453',num2str(sathh))
So, in line 188 I need to have the new values of parameterA.
Any ideas?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import and Export에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!