UI Callback error when writing a GUI as an app?
6 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
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');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!