The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: txt files, read and write
Replies: 7   Last Post: Oct 1, 2013 8:51 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]

Posts: 9,850
Registered: 6/7/07
Re: txt files, read and write
Posted: Sep 30, 2013 7:35 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 9/30/2013 5:43 PM, TideMan wrote:

> One way of retaining the structure of your file is to read it in
> holus bolus, then write it out the same way:
> fid=fopen('myfile.txt','rt');
> a=fscanf(fid,'%c'); % Now a is a long string containing everything,

including CR LF tabs etc etc
> fclose(fid);
> % Make the changes in a
> a=strrep(a,'OldNumber','NewNumber');
> etc
> % Write out the new version
> fid=fopen('myfile_new.txt','wt');
> fprintf(fid,'%c',a);
> fclose(fid);

Issa' ok if the replacement string is same length as the original and/or
the file format isn't fixed width--otherwise even this may not produce
the correct result by shifting fields left/right depending on the change
in width.

If the CFD program is one of the old Fortran-based ones, it may matter;
not enough info from OP to tell.


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.