微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Octave (GUI):错误输出并带有特殊符号“[square]”,尽管相同的代码适用于“Octave-online”

如何解决Octave (GUI):错误输出并带有特殊符号“[square]”,尽管相同的代码适用于“Octave-online”

Octave 6.1.0 (GUI)

这是 Octave: How to turn a vector of integers into a cell array of strings? 的衍生产品。

>> a = 1:3;
>> cellstr(int2str(a(:)))
ans =
{
  [1,1] = "[square]" 
}

enter image description here

虽然输出应该是:

ans =
{
  [1,1] = 1
  [2,1] = 2
  [3,1] = 3
}

octave-online.net

enter image description here

如何解决这个问题?

ps:仅供参考,不作为答案,没有此问题的解决方法cellstr(num2str(a(:)))

解决方法

这是由一个可怕的初学者错误造成的。

问题下的第一个帮助评论已经指明了方向。

  1. 如果在线 Octave 与您的 GUI 完全不同,那可能是您的错。

  2. 为了发现问题,请检查可能导致差异的函数:

    >> which('num2str')

    'num2str' 是文件 C:\Users\USERNAME\AppData\Local\Programs\GNU Octave\Octave-6.1.0\mingw64\share\octave\6.1.0\m\general\num2str 中的一个函数。米

    >> which('cellstr')

    'cellstr' 是来自文件 libinterp/octave-value/ov-cell.cc 的内置函数

    which('int2str')

    >> which('int2str')

    'int2str' 是一个变量`

  3. 由于某种未知原因,我只测试了其他函数,而不是“int2str”,因此我在使用阴影函数时偶然发现了错误:

    >> strcat('x',num2cell(int2str(1:10)))

    error: int2str(10): out of bound 3 (dimensions are 1x3)

    (注意:变量 'int2str' 阴影函数)

  4. 无论出于何种原因,我不小心通过分配 int2str = [1:3] 隐藏了该函数,导致了奇怪的行为。

Arbeitsumgebung = 工作环境: enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。