MATLAB: Creating a pushbutton and callback function

pushbutton callback function uicontrol

I could not find the right answer after a long search.
I want to create several pushbuttons in the script:
PushButton = uicontrol(gcf,'Style', 'push', 'String', 'Next', ... 'Position', [300 10 30 30], ...
'CallBack', 'PushB');
Then when I push the pushbutton I want the program to run a related function
function PushB_Callback('variables')
display('I pushed the pushbutton')
end
How do I do this?
thanks

Best Answer

Try
function myButtonTest()
PushButton = uicontrol(gcf,'Style', 'push', 'String', 'Next','Position', [300 10 30 30],'CallBack', @PushB);
function PushB(source,event)
display('I pushed the pushbutton')
end
end
For more information, check out the example in the documentation.