How can I change specific value located in a line in a text file incrementally.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ND
el 8 de Jun. de 2015
Comentada: ND
el 11 de Jun. de 2015
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 comentario
Star Strider
el 8 de Jun. de 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.
Respuesta aceptada
Walter Roberson
el 8 de Jun. de 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 comentarios
Walter Roberson
el 8 de Jun. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!