无法在Octave中加载文件

Ovi*_*diu 5 load octave

如果我弄错了,请提前道歉.这是我在这里发表的第一篇文章(我相信会有很多人关注).

我有一个文件,我想加载到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
Run Code Online (Sandbox Code Playgroud)

其中第一列描述了点的名称,而其余列表示其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'
Run Code Online (Sandbox Code Playgroud)

我也试过简化文件,只留下坐标并将文件视为CSV,但我一直遇到类似的错误.

am3*_*304 8

我认为load仅适用于数据文件,不适用于文本文件.你可以使用csvread,dlmread,textscantextread.检查文档以了解调用每个函数的正确语法.

以下是不同的方法:

  1. load 你发现不起作用

    x = load('test.txt')

     error: value on right hand side of assignment is undefined
    
    Run Code Online (Sandbox Code Playgroud)
  2. 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
    
    Run Code Online (Sandbox Code Playgroud)
  3. 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
    
    Run Code Online (Sandbox Code Playgroud)
  4. 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);
    
    Run Code Online (Sandbox Code Playgroud)

我还没有textread,但你明白了.