Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
ND
ND le 8 Juin 2015
Commenté : ND le 11 Juin 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 commentaire
Star Strider
Star Strider le 8 Juin 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.

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 8 Juin 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 commentaires
Walter Roberson
Walter Roberson le 8 Juin 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
ND
ND le 11 Juin 2015
Thank you Walter That's fine

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by