Is it possible to open a text file and update its contain and save it
again using matlab?If yes,how?Thanks.
|
|
0
|
|
|
|
Reply
|
kahboon (11)
|
4/12/2008 3:36:03 AM |
|
In article <5b4bd526-a7fe-4b8f-86e1-8f169410767d@v26g2000prm.googlegroups.com>,
<kahboon@gmail.com> wrote:
>Is it possible to open a text file and update its contain and save it
>again using matlab?If yes,how?Thanks.
Yes if you open it with fopen() with 'at+' as the access.
However, there are a bunch of pitfalls to watch out for, especially
since it is a text file. You cannot, for example, shorten a line
except by re-writing *everything* to the end of the file. And there
is no way to shorten a file in Matlab (without calling out to
ActiveX or a mex routine), which is true whether the file is text
or binary.
Usually if you need to update a file that is not a binary file with
fixed field widths, then the easiest thing to do is to copy from the
input file to a new file until you get to the part you want to change,
write out the changed version, skip over the old stuff in the input file,
then copy the rest of the input file to the new output file, and finally
after closing the files and ensuring that everything went okay, rename
the new file to have the old file's name.
--
"Product of a myriad various minds and contending tongues, compact of
obscure and minute association, a language has its own abundant and
often recondite laws, in the habitual and summary recognition of
which scholarship consists." -- Walter Pater
|
|
0
|
|
|
|
Reply
|
roberson2 (8067)
|
4/12/2008 4:16:45 AM
|
|