hObject, eventdata and handles not return double in R2016a

1 次查看(过去 30 天)
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.

采纳的回答

Jan
Jan 2016-4-26
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.

更多回答(2 个)

Walter Roberson
Walter Roberson 2016-4-26
编辑:Walter Roberson 2016-4-26
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 2016-4-26
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.

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by