필터 지우기
필터 지우기

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