Append text using fprintf

16 visualizaciones (últimos 30 días)
Michael Hansen
Michael Hansen el 14 de Nov. de 2016
Respondida: Walter Roberson el 14 de Nov. de 2016
Hi,
I'm trying to open a file and append data using fprintf.
For instance I have one line of the file
0001 1000 2000 mat1 0 10
I want to be able to append some text after the 10:
0001 1000 2000 mat1 0 10 289.6 259.6 etc..
How would I accomplish this? Do I use fprintf?
Thanks,
Mike

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Nov. de 2016
You can only use fprintf() to append to a line of a file in one narrow case:
  • the line to be appended to is the very last line of the file; and
  • the line to be appended to does not end up carriage return or new line; and
  • the file was not created in DOS mode ending in control-Z
In short, you can only append if the file just abruptly ends at the point that you want to append.
In this narrow case, open the file with 'a' or 'at' or 'a+' or 'at+' access mode and fprintf() will append to it.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by