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
}
How to fix this?
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.
If the online Octave is totally different from your GUI, it is probably your fault.
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`
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)
For whatever reason, I had accidentally shadowed the function by assigning int2str = [1:3]
, leading to the strange behaviour.