help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Writing a commented output to file


From: James Sherman Jr.
Subject: Re: Writing a commented output to file
Date: Tue, 5 May 2009 10:40:46 -0400

This might seem like a bit of a hack, but if you're on linux you could do something like

save tmpfile variable -ascii
system('echo \'comment line 1\' > filename');
system('echo \'comment line 2\' >> filename');
system('cat tmpfile >> filename');

The syntax maybe off, but hopefully I've conveyed the idea.  I assume there is something similar if you're using windows.

Hope this helps.

James

On Tue, May 5, 2009 at 7:55 AM, AlexG1 <address@hidden> wrote:

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.

_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

[Prev in Thread] Current Thread [Next in Thread]