How can I set the string of a pushbutton using another pushbutton created with uicontrol ?

Inside Main Function (creates a pushbutton in separate figure)
uicontrol('Style','Pushbutton','Callback',@command_fc);
Separate function (another .m file) (set the string of pushbutton1 to 100 in the main figure)
function [ ] = command_fc( hObject, handles)
set(handles.pushbutton1,'String','100');
end
The error I get when I try this:
No appropriate method, property, or field
'pushbutton1' for class
'matlab.ui.eventdata.ActionData'.
Error in command_fc (line 5)
set(handles.pushbutton1,'String','100');
Error while evaluating UIControl Callback

Answers (1)

When you specify the callback function, you use the syntax '@command_fc', which means that the function can only have the default parameters: source handle and event-data. When you define the function 'command_fc', you are trying to use the second argument as 'handles', which appears to be custom argument and can not be mapped to event-data object (which is supposed to be there).
If you want to have additional arguments in your callback methods, you need to define them. Refer to the following link for more information on the syntax and the concept.
https://www.mathworks.com/help/matlab/creating_plots/callback-definition.html#buhztrr-8

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Asked:

on 9 Feb 2017

Answered:

on 15 Feb 2017

Community Treasure Hunt

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

Start Hunting!