如果我有什么不对的地方,请提前道歉。这是我在这里的第一篇文章(我相信会有很多人关注)。
我有一个文件要加载到 Octave 中,但它不起作用。它是一个纯文本文件 (.txt)。
该文件是同类文件,其中几行的摘录如下所示:
0023,225.935,341.770,17.658
0024,225.935,341.758,17.782
LTAX17,228.152,353.935,17.665
LTAX24,288.304,332.878,24.074
其中第一列描述点的名称,而其余列表示其 3D 坐标。
我尝试过的一些选项(但不限于这些)没有成功。
x=load(text.txt)
error: scalar cannot be indexed with .
error: evaluating argument list element number 1
x=load("-text", "text.txt")
warning: load: file found in load path
error: load: empty name keyword or no data found in file 'text.txt'
x=fileread(text.txt)
warning: load: file found in load path
error: load: empty name keyword or no data found in file 'text.txt'
我也尝试过简化文件,只留下坐标并将文件视为 CSV,但我不断收到类似的错误。
最佳答案
我想 load
仅适用于数据文件,不适用于文本文件。您可以使用 csvread
, dlmread
, textscan
或 textread
.检查 documentation关于调用这些函数的正确语法。
以下是不同的方法:
load
正如你发现的那样不起作用x = load('test.txt')
error: value on right hand side of assignment is undefined
csvread
有效但将所有非数字值转换为 0
x = csvread('test.txt')
x = 23.00000 225.93500 341.77000 17.65800 24.00000 225.93500 341.75800 17.78200 0.00000 228.15200 353.93500 17.66500 0.00000 288.30400 332.87800 24.07400
dlmread
与 csvread
的工作方式相同x = dlmread('test.txt')
x = 23.00000 225.93500 341.77000 17.65800 24.00000 225.93500 341.75800 17.78200 0.00000 228.15200 353.93500 17.66500 0.00000 288.30400 332.87800 24.07400
textscan
有效,结果存储在元胞数组中fid = fopen('test.txt');
x = textscan(fid,'%s %f %f %f','Delimiter',',')
x = { [1,1] = { [1,1] = 0023 [2,1] = 0024 [3,1] = LTAX17 [4,1] = LTAX24 } [1,2] = 225.94 225.94 228.15 288.30 [1,3] = 341.77 341.76 353.94 332.88 [1,4] = 17.658 17.782 17.665 24.074 } >> fclose(fid);
我还没做
textread
,但你明白了。
关于load - 无法在 Octave 中加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26995793/