I have a GUI with a variable number of uicontrol pushbuttons which share a single callback function. In order to make this work, I am using the value of each of the buttons to determine how to handle the data being given. I assumed I would be able to use get(gcbo,'Value') in the callback function to determine which button was pressed, but for every button it simply returns 1. I have checked that each uicontrol object has a unique value. Here is a simplified example of my code:
handles.browse(i) = uicontrol('Style','pushbutton',... 'String','...',... 'Value',i,... 'TooltipString','Browse for a file.',... 'Position',[5 ypos-20 20 27],... 'Callback', @Browse); function Browse(varargin) val = get(gcbo,'Value'); [filename,path,index] = uigetfile('*.mat','Locate File'); if index output{val} = [path filename]; endend
Please keep in mind that I am working with version R2010b, though this shouldn't be an issue.
Best Answer