使用特定格式在Octave中加载文本数据 [英] Loading text data in Octave with specific format
问题描述
我有一个我想要存储的数据集,并且能够在Octave中加载
I have a data set that I would like to store and be able to load in Octave
18.0 8 307.0 130.0 3504. 12.0 70 1 "chevrolet chevelle malibu"
15.0 8 350.0 165.0 3693. 11.5 70 1 "buick skylark 320"
18.0 8 318.0 150.0 3436. 11.0 70 1 "plymouth satellite"
16.0 8 304.0 150.0 3433. 12.0 70 1 "amc rebel sst"
17.0 8 302.0 140.0 3449. 10.5 70 1 "ford torino"
15.0 8 429.0 198.0 4341. 10.0 70 1 "ford galaxie 500"
14.0 8 454.0 220.0 4354. 9.0 70 1 "chevrolet impala"
14.0 8 440.0 215.0 4312. 8.5 70 1 "plymouth fury iii"
14.0 8 455.0 225.0 4425. 10.0 70 1 "pontiac catalina"
15.0 8 390.0 190.0 3850. 8.5 70 1 "amc ambassador dpl"
它不起作用IM当我尝试使用时,中间地:
It does not work immediately when I try to use:
data = load('auto.txt')
有没有办法从给定格式的文本文件加载,或者我需要将其转换为例如
Is there a way to load from a text files with the given format or do I need to convert it to e.g
18.0,8,307.0,130.0,3504.0,12.0,70,1
...
编辑:
删除最后一行并修复一半数字,例如3504. - > 3504.0
然后使用:
Deleting the last row and fixing the 'half' number e.g. 3504. -> 3504.0 and then used:
data = load('-ascii','autocleaned.txt');
将所需数据加载到Octave中的矩阵中。
Loaded the data as wanted in to a matrix in Octave.
推荐答案
load
通常用于加载octave和matlab二进制文件,但可用于加载像你这样的文本数据。您可以使用 - ascii
选项加载数据,但在将文件放入 load $ c之前,您必须稍微重新格式化文件$ c>即使启用了
- ascii
选项。使用一致的列分隔符即。只是一个标签或逗号,使用完全数字而不是 3850。
并且不要使用字符串。
load
is usually meant for loading octave and matlab binary files but can be used for loading textual data like yours. You can load your data using the "-ascii"
option but you'd have to reformat your file slightly before putting it into load
even with the "-ascii"
option enabled. Use a consistent column separator ie. just a tab or a comma, use full numbers not 3850.
and don't use strings.
然后你可以做这样的事情让它工作
Then you can do something like this to get it to work
DATA = load("-ascii", "auto.txt");
这篇关于使用特定格式在Octave中加载文本数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!