popup-menu not changing rectangle facecolor

2 views (last 30 days)
ikenna
ikenna on 12 Nov 2013
Answered: Walter Roberson on 12 Nov 2013
I have a problem with the popup menu being able to change a rectangle color. I want the popup menu to change the rectangle color when it is clicked on this is my code below. Please any help would be so appreciated.
% --- 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])
title('Rect')
AND the popup-menu is below. Please do you know how I can comment a code on this site???
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
global hrect
x=get(hobject,'value');
switch x
case 1
r=get(hrect,'value');
set(hrect,'backgroundcolor','r')
case 2
r=get(hrect,'value');
set(hrect,'backgroundcolor','g')
case 3
r=get(hrect,'value');
set(hrect,'backgroundcolor','b')
case 4
r=get(hrect,'value');
set(hrect,'backgroundcolor','y')
end

Answers (1)

Walter Roberson
Walter Roberson on 12 Nov 2013
Rectangles do not have background colors. They only have FaceColor.

Categories

Find more on General Applications in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!