I was trying to use a string as a object handle within a for loop to save space as following:
function pushbutton1_Callback(hObject, eventdata, handles)for Button = 1 Button = num2str(Button); Obj = strcat('handles.Num',Button); set(str2func(Obj), 'ForegroundColor','red') set(handles.Num1, 'ForegroundColor','red')end
I would like to use Obj to replace handles.Num1. is there any way to do this?
Best Answer