Writing callback for a pushbutton
조회 수: 2 (최근 30일)
이전 댓글 표시
So I'm trying to calculate a sum to a custom N, which a user writes into a uicontrol/edit field, but I can't seem to get the callback right.
This is how I create the edit field:
handles.M1_8.up = uicontrol ('Style','edit',...
'String','n',...
'FontSize',10,...
'Position',[215 415 50 20]);
And this is the pushbutton:
handles.M1_8.calculate = uicontrol ('Style','pushbutton',...
'String','Calculate',...
'Position',[320 305 60 25],...
'Callback',@(~,~,handles) (calculate8_Callback(handles)));
And here's my function it's supposed to execute when pressing the Calculate button:
function calculate8_Callback(handles)
val = str2num(get(handles.M1_7.up,'String'));
Now, when I click the button, it says "Not enough input arguments." to the line where I wrote the callback to the pushbutton.
Any ideas why it's not working.
댓글 수: 0
채택된 답변
Sean de Wolski
2013년 5월 24일
The issue is in how you created the callback:
handles.M1_8.calculate = uicontrol ('Style','pushbutton',...
'String','Calculate',...
'Position',[320 305 60 25],...
'Callback',@(~,~,handles) (calculate8_Callback(handles)));
The callback right now expects three inputs, ~,~,handles. However, is only gets two, the source and the eventdata. This should work as the calback:
@(~,~) (calculate8_Callback(handles)));
During the creation of the anonymous function, a snapshot of handles will be taken and then passed into calculate8_Callback.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!