How do I use a vector to change the color of multiple panels in the GUI interface?
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm trying to make an interactive piano scale display with a drop down menu.
I'd like to have options in a drop down menu change the color of the panels I've placed.
I looked into the unipanel function but I can't figure out how to use it the way I want to.
I haven't coded much yet but I have modeled a GUI with 12 different panels in the desired placement.
I have attached a screen shot of what I've made so far.
If you are experienced in Matlab's GUI, any of your input would be very helpful.
Thanks.
댓글 수: 2
Geoff Hayes
2017년 1월 19일
Timothy - what is the vector that you mention in your title? Does it have twelve elements/colours, one for each of the uipanels? Please clarify and perhaps show some of your code.
답변 (1개)
Jorge Mario Guerra González
2017년 1월 19일
I dont understand exactly what are you trying to do, one way to change the colour of the objects in the GUI is this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176754/image.png)
The code to do that is this.
function pushbutton1_Callback(hObject, eventdata, handles) %button callback
picker=uisetcolor; %opens the picker
set(handles.uipanel1,'BackgroundColor',picker); %set the property
guidata(hObject, handles); %update handles
댓글 수: 3
Jorge Mario Guerra González
2017년 1월 20일
I'm not a computer scientist either. Colours are coded in RGB notation, meaning that a Colour has three components, therefore, matrix size should be (3x12).
Check at the way of doing it using the menu.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/185509/image.png)
the code to do that is:
function popupmenu1_Callback(hObject, eventdata, handles)
B=get(handles.popupmenu1,'value');
switch B
case 1
colour=[1 0 0];
case 2
colour=[0 1 0];
case 3
colour=[0 0 1];
case 4
colour=[0.5 0.5 0.5];
case 5
colour=[0.49412 0.18431 0.55686];
end
set(handles.uipanel1,'BackgroundColor',colour);
guidata(hObject, handles);
See how you can code each colour using the vectors, if you want to know what the RGB notation for a colour is, use uisetcolor
I hope this solves your question
Walter Roberson
2017년 1월 20일
Create a vector of handles,
ph = [handles.uipanel1, handles.uipanel2, handles.uipanel3, ... ];
then loop,
for K = 1 : length(ph)
set(ph(K), 'BackgroundColor', PanelColorMap(K, :) );
end
where PanelColorMap is a 12 x 3 array, one RGB triple per row.
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!