MATLAB: Unexpected behaviour from ishandle()

ishandleMATLAB

Hi,
In a script, I was checking the existence of a plot handle to either make a new plot or to change the x/y data. Surprisingly this didn't work by initially setting the plot handle to []. Reason:
>> ishandle( [] )
ans =
[]
which sort of makes sense.
However, my next step was to initialise the plot handle to 0, which also didn't work, and this was the real surprise:
>> ishandle( 0 )
ans =
1
Even though
>> ishandle( 1 )
ans =
0
Does anybody why zero would be a valid graphics or Java object handle?
Thanks,
Temu

Best Answer

On MATLAB versions prior to R2016b zero is the handle to the graphics root (i.e. the parent of all graphics figures):
For compatilbility using zero is still permitted in later versions.