How do I use a vector to change the color of multiple panels in the GUI interface?

2 ビュー (過去 30 日間)
Timothy Conklin
Timothy Conklin 2017 年 1 月 19 日
コメント済み: Walter Roberson 2017 年 1 月 20 日
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 件のコメント
Timothy Conklin
Timothy Conklin 2017 年 1 月 19 日
This is what the ugly GUI looks like so far.
Geoff Hayes
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
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.
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
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.
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
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 ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by