How do I use a vector to change the color of multiple panels in the GUI interface?
2 次查看(过去 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.
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.
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!