Filter löschen
Filter löschen

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

5 Ansichten (letzte 30 Tage)
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 Kommentar
Star Strider
Star Strider am 8 Jun. 2015
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 8 Jun. 2015
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 Kommentare
Walter Roberson
Walter Roberson am 8 Jun. 2015
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Environment and Settings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by