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

1 Ansicht (letzte 30 Tage)
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

Antworten (1)

Saurabh Gupta
Saurabh Gupta am 15 Feb. 2017
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

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by