MATLAB: Does stop(Timer) works, while Timer.stop does not

MATLABtimer

Using Timer Objects, I noticed some behaviour I could not explain.
Creating a timer with fixed rate, I was not able to stop it with Timer.stop(). However, stop(Timer) does work. What am I missing?
Timer =timer('Period', 1);
Timer.TimerFcn = @(myTimerObj, thisEvent)disp('1 second has elapsed');
Timer.ExecutionMode = 'fixedRate';
Timer.start();
pause(2)
stop(Timer); %<----works
%Timer.stop; %<----does not work

Best Answer

That's certainly an interesting behaviour and it took me a while to figure out what is actually happening. It's an unintended side effect of the matlab.mixin.SetGet abstract class from which timer derives. In my opinion, it's a bug, which I'll report. Whether mathworks sees it this way and certainly whether they do anything about it is anybody's guess.
The timer class derives from matlab.mixin.SetGet which gives it an interface that allows you to read/write properties of the class using e.g. get(Timer, 'Period') and set(Timer, 'Period', value). By default, this class also also you to abbreviate the property name to anything that is non-ambiguous. It also ignore case. So, in the above example, you can also write get(Timer, 'p') since the Period property is the only one that starts with p, regardless of case. The same happens when you use dotted notation to access properties, i.e. you can write Timer.p = 5. edit: That last sentence was wrong, matlab.mixin.SetGet does not affect dotted notation, it's the undocumented class attribute TruncatedProperties that does that.
The scoping rules for the syntax method(obj) and obj.method are slightly different. In the first case, matlab only search for functions and in the second case it also looks at properties (note that this is not documented, I may have things slightly wrong here). So when you write Timer.stop, matlab looks at the properties that starts with stop. It finds one and only one and thus ends up invoking get(Timer, 'StopFcn') and returns you the content of that property instead of invoking the stop method.
This doesn't happens with Timer.start because there are two properties that starts with start. Since that doesn't resolve to a unique property matlab ends up invoking the start method.
edit: After some more testing, I was slightly wrong about the root of the problem. It's not matlab.mixin.SetGet that is the culprit. It's actually one of the class attribute, TruncatedProperties=true that is the cause of the problem. TruncatedProperties is undocumented unfortunately.