Conversion from logical no longer works in MATLAB 2015a
Show older comments
Hello,
I have a function that worked in MATLAB 2014a but that no longer works in MATLAB 2015a.
if hw && ishandle(hw)
hw is a uicontrol, the error message returned is listed below.
Conversion to logical from matlab.ui.control.UIControl is not possible.
Can you tell me what has changed in 2015a to cause this error?
Thanks.
Answers (1)
You should use
ishghandle(...)
for graphics handle objects, but if hw is a graphics handle object then I'm not sure what you expect it to be on implicit conversion to a logical type.
In previous versions all graphics handles where doubles, but now they are actual class objects so the above function will test if it is a valid graphics handle or not.
Also
isgraphics(...)
and
isvalid(...)
seem to do very similar tests. I always forget the subleties of their usage as I always use ishghandle to test, for example, that an axes is valid before using it.
2 Comments
Nick
on 3 Sep 2015
Walter Roberson
on 4 Sep 2015
Before "if hw" would be checking to see if hw was anything other than 0. A handle could be 0 if it was the graphics root, now called groot. Or a handle could be 0 if the program had deliberately zeroed it to indicate that it was no longer valid, which is a mixup between Value and State that has come back to bite the programmer in the Fundament(al Datatypes)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!