load - 无法在 Octave 中加载文件

标签 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

其中第一列描述点的名称,而其余列表示其 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 , textscantextread .检查 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
    
  • dlmreadcsvread 的工作方式相同

    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/

    相关文章:

    ruby - 是否可以从大型 Rub​​y 模块加载/只需要一个函数?

    wpf - CefSharp 使用浏览器登录加载页面

    matlab - 在 MATLAB 中使用 SVD 压缩图像

    matlab - 在 Matlab 中加载 Octave 创建的 ASCII 格式 .mat 文件

    javascript - 加载完成前隐藏 -jquery

    linux - 用于 CPU 负载监控的 Shell 脚本

    java - 如何动态编译和加载外部java类?

    octave - imshow() 对于 Octave 中的 int16 数组不显示任何内容

    macos - 在 Mac OSX 中的 Iterm/Zsh/Omgzsh 上运行 Octave-cli

    sockets - 带倍频程的 pkg 负载 socket