Writing a commented output to file

AlexG1 alxgel at gmail.com
Tue May 5 06:55:53 CDT 2009


Hi,

I'm writing a script which eventually needs to write a matrix to a text
file, and prepend some comments to it (e.g. title line and the starting
conditions that led to the output).

For example, if the matrix is

a = 
1 2 3
4 5 6
7 8 9

I want the output file to look like that:

% Some comment 1
% Some comment 2
1 2 3
4 5 6
7 8 9

Now, since the matrices can get quite big I don't want to use printf() for
every line since it may take a lot of time. Ideally I'd like to use save
-ascii to save the matrix and printf() for the comments.

The problem is this - if I'm using save to write the matrix first I can't
prepend the comments since there is no way to open a file for prepending but
only for appending.
If I write the comments first and then call save -ascii it just overwrites
the contents of the output file and the file will only contain the matrix
without the comments.

Any ideas on how I can get both without just using printf() for everything?

Thanks,

Alex 


-- 
View this message in context: http://www.nabble.com/Writing-a-commented-output-to-file-tp23385991p23385991.html
Sent from the Octave - General mailing list archive at Nabble.com.



More information about the Help-octave mailing list