hObject, eventdata and handles not return double in R2016a

1 view (last 30 days)
Hi I am running a GUI program under R2016a and found the hObject, eventdata and handles are not return doubles as in R2014a before, which give me error 'Expected input to be one of these types: numeric, instead its type was matlab.ui.Figure' and 'error while evaluating UICotrol Callback'. Is there any way to let these functions return doubles as before, or alternate way to make the whole GUI work? Thanks very much.

Accepted Answer

Jan
Jan on 26 Apr 2016
Matlab has introduced a modern and more powerful graphics engine called "HG2". It was a mess, that grahpic handles were doubles before, because this let users misuse them as numbers. It seems like your code did that and in consequence it fails now.
The HG1 and HG2 graphics systems are not compatibel. So if you want to run the GUI without changes, you have to start it in an old Matlab version. If you want to run it in a modern Matlab version, adjust the code such the graphic handles are treated as graphics handles.

More Answers (2)

Walter Roberson
Walter Roberson on 26 Apr 2016
Edited: Walter Roberson on 26 Apr 2016
What is it that is expecting its input to be numeric instead of figure?
There is no way to configure the functions to return numeric handles now.
The best alternative method is to change your code to not expect doubles.
If somehow that cannot be done, then take double() of the handle and use that as the numeric value. In another couple of releases this method will no longer be supported.

Mike Garrity
Mike Garrity on 26 Apr 2016
There was quite a bit of documentation on this as part of the R2014b release. This page from the transition guide will probably be helpful. In addition, there was a series of posts (starting with this one) on Loren's blog that might be helpful. There's also this tool on the File Exchange which can identify common issues.
The short version is that it is possible to coerce the handles into doubles, but it's really much better to identify why your code is assuming that they are doubles and fix that. Where is that error message coming from? It sounds like it's from validateattributes. If the call to validateattributes is in your code, you might be able to add matlab.ui.Figure to the list of accepted classes.

Categories

Find more on Graphics Performance 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!