[英]Cannot load a file in Octave
Apologies in advance if I get something wrong. 如果我弄错了,请提前道歉。 This is my first post here (I'm sure there will be many to follow). 这是我在这里发表的第一篇文章(我相信会有很多帖子可以关注)。
I have a file I want to load into Octave but it doesn't work. 我有一个文件,我想加载到Octave但它不起作用。 It is a plain text file (.txt). 它是纯文本文件(.txt)。 The file is homogeneous and an excerpt of a few lines from it look like this: 该文件是同类的,从它的几行的摘录看起来像这样:
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
where the first column depicts the name of the point while the rest represent its 3D coordinates. 其中第一列描述了点的名称,而其余列表示其3D坐标。
Some of the options I've tried (but not limited to these) were unsuccessful. 我试过的一些选项(但不限于这些)都没有成功。
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'
I have also tried simplifying the file, leaving only the coordinates and treating the file as a CSV but I keep getting similar errors. 我也试过简化文件,只留下坐标并将文件视为CSV,但我一直遇到类似的错误。
I think load
is only for data files, not for text files. 我认为load
仅适用于数据文件,而不适用于文本文件。 You might to use csvread
, dlmread
, textscan
or textread
. 您可以使用csvread
, dlmread
, textscan
或textread
。 Check the documentation as to the correct syntax for invoking each of these functions. 检查文档以了解调用每个函数的正确语法。
Here are the different approaches: 以下是不同的方法:
load
does not work as you found out 你发现load
不起作用
x = load('test.txt') x = load('test.txt')
error: value on right hand side of assignment is undefined
csvread
works but converts all non-numeric values to 0
csvread
工作但将所有非数字值转换为0
x = csvread('test.txt') 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
works in the same way as csvread
dlmread
工作方式与csvread
相同
x = dlmread('test.txt') 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
works, results are stored in a cell array textscan
工作,结果存储在单元格数组中
fid = fopen('test.txt'); fid = fopen('test.txt');
x = textscan(fid,'%s %f %f %f','Delimiter',',') 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);
I haven't done textread
, but you get the idea. 我没有做过textread
,但是你明白了。
trying copying your data to Microsoft's wordpad and save the file as a ".dat" extension and load it into Octave. 尝试将数据复制到Microsoft的wordpad并将文件保存为“.dat”扩展名并将其加载到Octave中。 Worked for me, hope the same works for you, good luck! 为我工作,希望同样适合你,祝你好运!
open a notepad give this format 打开记事本给出这种格式
# Created by Octave 4.2.1, Sat Jun 03 19:48:46 2017 GMT <unknown@Asus>
# name: a
# type: matrix
# rows: 6
# columns: 3
60 30 50
20 45 65
24 23 23
23 32 32
23 65 65
34 54 45
save as file.data 另存为file.data
open octave 开八度
>>load file.data
>>a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.