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

1 次查看(过去 30 天)
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

回答(1 个)

Saurabh Gupta
Saurabh Gupta 2017-2-15
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

类别

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