How specific lines in a text file can be updated many times ?

1 visualizzazione (ultimi 30 giorni)
Dear all, Please how can I update specific lines or specific matrix which found in the middle of a text file. Actually, I have jacobian matrix needs to be updated at every iteration and I should save the changes in the same file.
Many thanks for your help in advance.
  2 Commenti
Cedric
Cedric il 23 Mag 2015
Why not computing/updating the Jacobian matrix directly in Fortran?
ND
ND il 26 Mag 2015
As my job should be done within Matlab, using Matlab just for calling and running other software packages.

Accedi per commentare.

Risposta accettata

dpb
dpb il 22 Mag 2015
Simple answer is "you can't, at least easily". Sequential text files are, well, "sequential". Even with the complex ways you could only make changes that were precisely the same length in the revised data as that changed.
A far better solution would be to make the changes in memory (which you have to do, anyway, to make anything happen) and then if you really, really, must save these data every iteration, use save to save the array in a more efficient manner than text. If you then must look at it at some point in text, then you can convert but there's really no need otherwise.
  21 Commenti
dpb
dpb il 29 Mag 2015
Well, I don't know what "the Fortran function" is in Matlab, but surely you've seen enough pieces of how to write whatever it is you want to write expounded upon here.
Try some code and see where you then actually fail and with a specific example of that problem we can answer a specific question. I don't really follow what you're lacking at this point...
Walter Roberson
Walter Roberson il 29 Mag 2015
Using the fortran() call makes it really simple. Instead of fopen/fprintf/etc to write out the new file, just use
fortran(DDSDDE,'file','partB.f');
Here, the variable that stores your symbolic expression should be a symbolic matrix, and it should be the same name as what you want to appear in the file. If you use a regular MATLAB matrix of symbolic expressions then there is the possibility that the output variable name will be "t0" instead of the name you want.
Side note: when you use fortran() in this form, there is the bonus that it will generate optimized code, using temporary variables to avoid computing the same thing multiple times. That's good for computation purposes, but does tend to make the code more difficult to understand.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su File Operations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by