MATLAB: How to change pushbutton background

backgrounddynamicfor loopguipushbutton

I constructed a number of pushbuttons by using the below loop, and now I want to change the background of each one when it was pressed.
for i = 1 : 8
for j = 1 : 7
btn(j,i) = uicontrol('Parent', figure_handle, ...
'Style', 'pushbutton', ...
'Position', [45+(i*51) 552-(j*50) 52 51],...
'Callback', @changeBG);
end
end
How can i get the correct button to pass to changeBG function? Can someone help me?
Thank you

Best Answer

I'd say :
for i = 1 : 8
for j = 1 : 7
btn(j,i) = uicontrol('Parent', figure_handle, ...
'Style', 'pushbutton', ...
'Position', [45+(i*51) 552-(j*50) 52 51],...
'Callback', {@changeBG,i,j}); % add too arguments to changeBG
end
end
then in changeBG, something like
function changeBG(hobject,evendata,i,j)
if i==1 && j==1
set(hobject,'Backgroundcolor','r') % red for i=1, j=1
elseif ....
% same kind of treatment for each of your button
elseif ....
elseif ....
elseif ....
end