How do I use a vector to change the color of multiple panels in the GUI interface?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Geoff Hayes
le 19 Jan 2017
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.
Réponses (1)
Jorge Mario Guerra González
le 19 Jan 2017
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 commentaires
Jorge Mario Guerra González
le 20 Jan 2017
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
le 20 Jan 2017
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.
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!