本文介绍了八度(GUI):错误的输出并带有特殊符号"[square]"尽管相同的代码在“八度在线"中工作,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

八度6.1.0(GUI)

这是

输出应为:

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

该如何解决?

p.s .:仅出于提供信息的目的,而不是作为答案,没有此问题的解决方法将是 cellstr(num2str(a(:))).

解决方案

这是由一个严重的初学者的错误引起的.

该问题下的第一条帮助性评论已经表明了方式.

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

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

    >>哪个('num2str')

    'num2str'是来自文件C:\ Users \ USERNAME \ AppData \ Local \ Programs \ GNU Octave \ Octave-6.1.0 \ mingw64 \ share \ octave \ 6.1.0 \ m \ general \ num2str的函数.m

    >>哪个('cellstr')

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

    which('int2str')

    >>哪个('int2str')

    'int2str'是变量`

  3. 由于某种未知原因,我仅测试了其他功能,而没有测试"int2str",因此我不小心发现了使用阴影函数时的错误:

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

    错误:int2str(10):超出边界3(尺寸为1x3)

    (注意:变量"int2str"阴影功能)

  4. 无论出于何种原因,我都通过分配 int2str = [1:3] 意外遮蔽了该函数,从而导致了奇怪的行为.

Octave 6.1.0 (GUI)

This is a spin-off from Octave: How to turn a vector of integers into a cell array of strings?.

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

While the output should be:

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

octave-online.net:

How to fix this?

p.s.: Only for your information and not as an answer, a workaround without this issue would be cellstr(num2str(a(:))).

解决方案

This is caused by a terrible beginner's mistake.

The first helping comment under the question has already shown the way.

  1. If the online Octave is totally different from your GUI, it is probably your fault.

  2. In order to find the problem, check the functions that might cause the difference:

    >> which('num2str')

    'num2str' is a function from the file C:\Users\USERNAME\AppData\Local\Programs\GNU Octave\Octave-6.1.0\mingw64\share\octave\6.1.0\m\general\num2str.m

    >> which('cellstr')

    'cellstr' is a built-in function from the file libinterp/octave-value/ov-cell.cc

    which('int2str')

    >> which('int2str')

    'int2str' is a variable`

  3. Since I have for some unknown reason tested only other functions, but not the 'int2str', I accidentally found out about the error when using the shadowed function instead:

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

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

    (note: variable 'int2str' shadows function)

  4. For whatever reason, I had accidentally shadowed the function by assigning int2str = [1:3], leading to the strange behaviour.

这篇关于八度(GUI):错误的输出并带有特殊符号"[square]"尽管相同的代码在“八度在线"中工作,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 12:13