function autobuttongenrate f = figure; numOfButtons = 7; p = uipanel(f,'Title','My Panel',... 'Position',[0 0 .3 1]); buttonHeightPercent = (100/(numOfButtons + (numOfButtons*0.1)))/100; unitDistanceBtwButtons = ((100 - (buttonHeightPercent*100*numOfButtons))/(numOfButtons+1))/100; bArr = zeros(1, numOfButtons); for n = 1:numOfButtons newButtonButtomMargin = 1 - ((unitDistanceBtwButtons + buttonHeightPercent) * n); bnew = uicontrol(p,'Style','pushbutton','String',n,... 'Value',n,... 'Units','normalized',... 'Position',[.1 newButtonButtomMargin .8 buttonHeightPercent],... 'Callback', @setmap); bArr(n) = bnew; end ax = axes('Parent',f,'Position',[.4 .25 .5 .5]); function setmap(source,event) src = source; eve = event; h = msgbox({'pushbutton pressed'}); end end
MATLAB: I am trying to programmatically create some GUI pushbuttons, but I am unable to retrieve the values passed in the callback. I want to find out the value and string attribute of the button pressed.
functionsguiguidematlab functionmatlab guiparameter passingprogrammatic gui
Best Answer