Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write a text file in octave without header

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?

like image 858
Riken Shah Avatar asked Aug 02 '26 20:08

Riken Shah


2 Answers

Use 'save -ascii', from the manual:

-ascii
Save a single matrix in a text file without header or any other information.
like image 112
Andy Avatar answered Aug 05 '26 08:08

Andy


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 ..., ... .

like image 21
Dilettant Avatar answered Aug 05 '26 09:08

Dilettant