How do i detect button pressed in uicontrol?

4 views (last 30 days)
Elsie
Elsie on 23 Jun 2014
Commented: Elsie on 24 Jun 2014
I have two buttons in my figure window, and i want to perform different operation for this two button, but i don't know how to detect which button is pressed? Thanks a lot.
f = figure;
u1 = uicontrol('Style','push', 'parent', f,'pos',...
[750 50 60 60],'string','Back','Enable','off','Callback','uiresume(gcbf)');
u2 = uicontrol('Style','push', 'parent', f,'pos',...
[830 50 60 60],'string','Next','Enable','off','Callback','uiresume(gcbf)');
align([u1,u2],'distribute','bottom');
if buttonBack is pressed...?
.....
end
if buttonNext is pressed..?
....
end

Answers (1)

Image Analyst
Image Analyst on 23 Jun 2014
You need to define separate callback functions, rather than 'uiresume(gcbf)' like you did.
I suggest you look at this GUIDE tutorial which will make it a lot easier than trying to manually create dozens of controls one at a time for your GUI, which can be rather tedious since, as you can see, there are a lot of input arguments you have to worry about. http://blogs.mathworks.com/videos/category/gui-or-guide/
  1 Comment
Elsie
Elsie on 24 Jun 2014
nice link! i am still learning. Thanks. i also think that writing all controls at a time is very difficult for further maintenance.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!