When I try to write a variable to text file in octave, by using this command save -text hey.txt X, the file get saved properly BUT with a header which I do not want.
File hey.txt
# Created by Octave 3.8.1, Wed Jun 08 10:03:36 2016 IST <kenden@kenden-Lenovo-G500>
# name: X
# type: matrix
# rows: 1686
# columns: 1
767
865
860
855... and so on.
How can I save a file without the header?
Use 'save -ascii', from the manual:
-ascii
Save a single matrix in a text file without header or any other information.
I suggest you use
csvwrite('hey.txt', X)
instead :-)
In case you want the header simply removed, someone at What is the fastest way to write a matrix to a text file in Octave? noted to use something like this (adapted to your case):
save -text hey.txt X
and then in bash et al.:
$> tail -n +6 hey.txt > headless_hey.txt
Which works nicely, as long as Octave uses 6 lines for the header.
Based on the observation, that comments start the line with a # one might eventually use other tools filtering based on that fact (not a fixed set of lines) like so:
$> sed /^#.*$/d hey.txt > commentless_hey.txt
or solutions based on grep -v ..., ... .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With