MATLAB: Push button not changing color

push button not changing color

I tried changing the color of a rectangle with the slider but unfortunately it changes the color of the rectangle button not the actual rectangle in the axes. I want the rectangle which is created to change when the slider button is clicked.
Below shows my code for the rectangle:
% --- Executes on button press in rect.
function rect_Callback(hObject, eventdata, handles)
% hObject handle to rect (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global hrect
global rectX
hrect = rectangle('Position',[28 28 20 20])
set(hrect,'FaceColor',[1 0 0])
This code below shows the slider bar and the push button to change it:
% --- Executes on button press in ChangeColor.
function ChangeColor_Callback(hObject, eventdata, handles)
% hObject handle to ChangeColor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global hrect
r=get(handles.slider1,'value');
b=get(handles.slider2,'value');
g=get(handles.slider3,'value');
set(handles.rect,'backgroundcolor',[r g b])
Thanks

Best Answer

Replace handles.rect with hrect