필터 지우기
필터 지우기

UI Callback error when writing a GUI as an app?

조회 수: 7 (최근 30일)
sicilian27
sicilian27 2015년 6월 15일
댓글: sicilian27 2015년 6월 16일
Hello everyone. I am writing a GUI as an app for a particular control application. I am using the normal class definition structure, defining my class with properties and then methods. This method is new to me in Matlab, but I believe I have done it correctly. However, when I try to set the Callback property for one of my UI controls and then evaluate the Callback, I get the following error:
%Undefined function 'COM_port_Callback' for input arguments of type 'matlab.ui.control.UIControl'.
Here are what I believe to be the two relevant sections of my code. I am writing this GUI without GUIDE and I felt no need to have a CreateFCN since nothing needed to execute upon creation. Avoiding this worked for other GUIS I have built, but if there is something special about doing it with the specifically defined class structure, then I would appreciate it if someone could provide input.
Here is my initialization of the UI element:
app.COM_port = uicontrol('Parent',app.panel2,'Style','edit',...
'Position',[90,68,50,20],...
'Units','normalized',...
'Callback',@COM_port_Callback,...
'FontUnits','normalized');
Furthermore, here is my callback function:
function COM_port_Callback(app,hObject,eventdata)
COM = str2num(get(app.COM_port,'String'));
I am unsure why the error is returned, and I would very much appreciate any input. By the way, both COM_Port and COM are initialized in the Properties section of my Class, so I don't believe that is the issue. Thank you for your help guys!

채택된 답변

Walter Roberson
Walter Roberson 2015년 6월 15일
uicontrol() Callback are invoked with graphics object and event data as arguments, both of which are created by the graphics system. Neither of those arguments are objects that are members of your class. MATLAB thus has no reason to invoke your class's COM_port_Callback.
You could experiment with something like,
app.COM_port = uicontrol('Parent',app.panel2,'Style','edit',...
'Position',[90,68,50,20],...
'Units','normalized',...
'Callback',@(src,evt) COM_port_Callback(app,src,evt),...
'FontUnits','normalized');
  댓글 수: 1
sicilian27
sicilian27 2015년 6월 16일
Thanks Walter! I figured it out and ended up doing something similar to that. Another quick questions. My class stores all my properties used in the single GUI script. Can I access the data stored in the those properties from another script?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by