Writing a commented output to file
James Sherman Jr.
shermanj at umd.edu
Tue May 5 09:40:46 CDT 2009
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 <alxgel at gmail.com> 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
> Help-octave at octave.org
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www-old.cae.wisc.edu/pipermail/help-octave/attachments/20090505/1c579581/attachment.html
More information about the Help-octave
mailing list