MATLAB: How to program a callback on a UICONTROL

pushbuttonuiconrol

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?

Best Answer

More than what you asked for...
PushButton = uicontrol(gcf, 'Style', 'push', 'String', 'Next', ...
'Position', [300 10 30 30], ...
'CallBack', @GraphCreator, ...
'UserData', 0);
function GraphCreator(PushButton, EventData)
newiter = get(PushButton, 'UserData') + 1;
if newiter > N
wd = warndlg('Reached end of graphs. Push again to start over');
uiwait(wd, 30); %30 second timeout on warning
if ishandle(wd) %only true if timed out
delete(wd)
end
set(PushButton, 'UserData', 0);
return
end
set(PushButton, 'UserData', newiter);
InputData = load(FileName{newiter});
fn = fieldnames(InputData);
thisdataname = fn{1};
create_graph(S.(thisdataname));
end