简体   繁体   English

以八度为单位写一个没有标题的文本文件

[英]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. 当我尝试用八度音程写一个变量到文本文件时,通过使用这个命令save -text hey.txt X ,文件得到了正确保存但是我不想要的标题。

File hey.txt 文件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: 使用手册中的“save -ascii”:

-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? 如果你想简单地删除标题,有人在Octave中将矩阵写入文本文件的最快方法是什么? noted to use something like this (adapted to your case): 注意到使用这样的东西(适合你的情况):

save -text hey.txt X

and then in bash et al.: 然后在bash等人:

$> tail -n +6 hey.txt > headless_hey.txt

Which works nicely, as long as Octave uses 6 lines for the header. 只要Octave使用6行代表标题,这样就可以很好地工作。 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 ... , ... . 或基于grep -v ... ,...的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM