MATLAB: Keep track of iterator in different pushbuttons

pushbutton

Hello all,
Being part of a larger project, I wish to iterate over a bunch of pushbuttons on a Figure Window, and display the iterator number on the Command Window. I have written something like
for iter = 1 : 5
uicontrol('style', 'pushbutton', 'position', [20 iter*30 50 20], 'string', 'Open...', 'callback', 'iter')
end
but this gives always
iter = 5
when invoking any of the five pushbuttons. What am I missing here?
Thanks for all the help! Gabriel

Best Answer

for iter = 1 : 5
uicontrol('style', 'pushbutton', 'position', [20 iter*30 50 20], 'string', 'Open...', 'callback', @(src,evt) disp( iter ))
end
should work. I don't really know what I would expect of 'iter' as a callback, but I guess you demonstrated what it does!