octaveoctave-gui

Wrong output and with a special sign "[square]" although same code works in "Octave-online"


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]" 
}

enter image description here

While the output should be:

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

octave-online.net:

enter image description here

How to fix this?

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


Solution

  • 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.

    Arbeitsumgebung = work environment: enter image description here