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

2 次查看(过去 30 天)
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 个评论
Cedric
Cedric 2015-5-23
Why not computing/updating the Jacobian matrix directly in Fortran?
ND
ND 2015-5-26
As my job should be done within Matlab, using Matlab just for calling and running other software packages.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2015-5-22
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 个评论
dpb
dpb 2015-5-29
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 2015-5-29
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by