MATLAB: If I want multiple buttons to run the same function when pressed, how to reference each button’s properties using a structure in the function itself

callback functionguipushbutton

I am trying to make a function/GUI that is put in nine buttons' callback function area. The function references the string of the button that was pressed and changes it. In the function, how do I make it so that I have a button tag to reference?
Here is my function code
function handles = buttonPress(hObject,handles)
if handles.String ~= ' '
handles.BackgroundColor=[1 0 0];
hold on
handles.BackgroundColor = [1 1 1];
else
if handles.whoseTurn.String=='o'
handles.String='o';
handles.turnNumber.String=str2num(handles.turnNumber.String)+1;
handles.whoseTurn.String='x';
elseif handles.whoseTurn.String=='x'
handles.String='x';
handles.turnNumber.String=str2num(handles.turnNumber.String)+1;
handles.whoseTurn.String='o';
end
end
end
I want to make it so that handles.TAG.String is used for every button, but I don't know how to make the tag change.

Best Answer

hObject.String is the string associated with the button that was clicked.