How can I change specific value located in a line in a text file incrementally.

2 次查看(过去 30 天)
I have a value needs to be changed many times. it can be consider as a force and I need to change this force incrementally. I know the line of it(120). For each value I have to run the software with this file ,then go on to the next value. For example the force is 100 KN I need to change this value 10 times. line (120)= Set-20-,3,value.
Many thanks
  1 个评论
Star Strider
Star Strider 2015-6-8
It would help if you attached your code (use the ‘paperclip’ or ‘staple’ icon, then ‘Choose file’ and ‘Attach file’) so we can see what ‘line 120’ is. Without that information it is very difficult help you.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2015-6-8
The response is the same as for your earlier question about updating text files many times. There has been no magic MATLAB call or magic MS Windows call developed in the last week that would allow a text file to be updated in place with text of a potentially different size.
This is a file system limitation on all file systems on all operating systems that MATLAB has ever worked on (except that it could in theory have been done under VMS when MATLAB was just getting started.)
  3 个评论
Walter Roberson
Walter Roberson 2015-6-8
A = regexp( fileread('first.inp'), '\n', 'split');
for Value = linspace(0,20,15) %new values to put in
A{120} = sprintf('%s,%d,%d,%f','Set-', 22, 2, Value); %format new content
fid = fopen('test2.inp', 'w');
fprintf(fid, '%s\n', A{:});
fclose(fid);
%then call the external routine
system(......)
end

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by