Adding a number to a string returns a vector of double values, which is expected:
>> ch = 'A', ch += 1 ch = A ch = 66
The in-place incrementing causes the type to become double instead of char.
The useful but inexplicable behavior is that using a boolean index causes the original type to be retained, and this is true even if all elements are modified:
>> ch = 'A', ch(isalpha(ch)) += 1 ch = A ch = B
How did it know the original type even if all elements of the input were being added numerically, and how is that different from the previous case? Is the
+= operator no longer an in-place operator in this context?