UI Callback error when writing a GUI as an app?
6 views (last 30 days)
Show older comments
sicilian27
on 15 Jun 2015
Commented: sicilian27
on 16 Jun 2015
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 Comments
Accepted Answer
Walter Roberson
on 15 Jun 2015
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');
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!