How do I program a callback on a UICONTROL?
이전 댓글 표시
I want to present several graphs such that when I click a push button beside a graph, the next in the series appears.
I tried the following code, but the push button those not influence the running.
PushButton = uicontrol(gcf,'Style', 'pushbutton', 'String', 'Next',
'Position', [300 10 30 30], 'Callback', 'pause');
How should I do this?
채택된 답변
추가 답변 (2개)
Jan
2011년 2월 9일
Try this at first:
PushButton = uicontrol(gcf,'Style', 'pushbutton', ...
'String', 'Next', ...
'Position', [300 10 30 30], ...
'Callback', @yourCallback);
function yourCallback(ObjH, EventData)
% ObjH is the button handle
FigH = ancestor(ObjH, 'figure'); % or: gcbf
set(FigH, 'Color', rand);
Then insert something more useful in the callback function. BTW: Searching in the documentation is always a good point to start from:
docsearch callback
댓글 수: 5
noga cohen
2011년 2월 9일
Jan
2011년 2월 9일
@noga: Please post the relevant part of the code.
noga cohen
2011년 2월 10일
K VdB
2016년 10월 24일
When I run the script noga cohen gave it says:
''All functions in a script must be closed with an 'end'.
When I close the script with an end it says:
''Function definitions are not permitted in this context.''
Walter Roberson
2016년 10월 24일
Only R2016b and later permit function definitions inside a .m file that does not start with the word "function" or "classdef" .
Anyhow: store the function inside GraphCreator.m and have the assignment to PushButton in a different routine.
카테고리
도움말 센터 및 File Exchange에서 Toolbox Distribution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!