Lacking a true `null` element in Octave, empty arrays have a special meaning. Essentially, they trigger a "deletion" of the specified LHS elements.
>> v = [1, 5, 8, 0];
>> v([1,3]) = [];
>> v
v =
5 0
Using `[]` or `''` is equivalent in that context.
In your second example, `v` has 0 elements. Trying to delete the first element results in an error. (The error message could be clearer though admittedly.)
For me that the error is slightly different:
>> v = {};
>> v(1)=''
error: A(I) = []: index out of bounds: value 1 out of bound 0
If you'd like to add a cell with the value `''` at the first position in the cell array `v`, you could use
v{1} = '';
or:
v(1) = {''};
Both variants should equivalently add a new cell element to the empty cell array v at the position 1 with the value `''`.
In your first example, the RHS is *not* an empty array. Thus, the deletion rules don't apply. Instead, the right hand side is converted to a 1x1 cell with the character '1' as the value of that single cell element.
I hope that helps.
Markus
Gesendet: Montag, 14. August 2023 um 15:25 Uhr
Von: "Ian McCallion" <ian.mccallion@gmail.com>
An: help-octave@gnu.org
Betreff: Bug in Octave 8.2.0
v = {};
v(1)='1'
produces:
v =
{
[1,1] = 1
}
Which is right. However
produces:
error: A(I) = []: index out of bounds: value 2 out of bound 1
This is surely wrong. I should be able to initialise the cell array with empty strings???
Cheers... Ian
---------- We are transitioning to a web based forum for community help discussions at
https://octave.discourse.group/c/help