hObject, eventdata and handles not return double in R2016a

조회 수: 2 (최근 30일)
Tian Wang
Tian Wang 2016년 4월 26일
답변: Mike Garrity 2016년 4월 26일
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에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by