You could potentially do something like this by overloading the functions SUBSREF and SUBSASGN for all the different types of objects (built-in or user-defined) that you want to change the indexing scheme for. An example of one way to overload methods for built-in types is given in my answer to this question. The drawbacks?...
- This would be a large and treacherous undertaking.
- It would break all of the built-in functions that rely on one-based indexing, meaning you'd have to basically rewrite most of MATLAB.
- Any code you might want to use from other MATLAB users, which would also rely on one-based indexing, would have to be rewritten.
In short, changing how built-in types handle indexing is not even remotely feasible. There is however another (albeit still somewhat treacherous) option making use of subclassing in MATLAB's OOP system. For example, you could make a new class double_zb
that inherits from the built-in double
class:
classdef double_zb < double
methods
function obj = double_zb(data)
if nargin == 0
data = 0;
end
obj = obj@double(data); % initialize the base class portion
end
end
end
Then you can extend double_zb
with specialized implementations of SUBSREF and SUBSASGN that take zero-based indices. However, using double_zb
objects instead of double
objects effectively in your code may require you to either re-implement all the other methods for double
objects or somehow implement converter methods for using double_zb
objects with double
methods. I'm not even sure of all the details involved in doing this, but I can certainly say that it would be a colossal headache.
My ultimate advice... stop worrying and learn to love the one-based indexing. ;)