Colors in Matlab as a vriable

5 visualizzazioni (ultimi 30 giorni)
Rao Maaz Bin Khalid
Rao Maaz Bin Khalid il 12 Gen 2021
Risposto: Steven Lord il 12 Gen 2021
I want the user to choose a color from a menu for my object. Can someone please suggest what the best way to do it is?
My object is in another function which I have called in the main script. The menu is also inside the function.
Part of Function:
Auto.Farbe = menu ('Wählen Sie eine Autofarbe aus' ,'Red','Yellow','Green');
Main script:
Farbe = Auto.Farbe;
patch('Vertices',Auto.Ecken,'Faces',Auto.Karosseire_Flaechen,'FaceColor',Farbe)
Any leads will be highly appreciated.

Risposte (2)

Stephen23
Stephen23 il 12 Gen 2021
Modificato: Stephen23 il 12 Gen 2021
Perhaps something like this:
M = [1,0,0;... red
1,1,0;... yellow
0,1,0]; % green
X = strcmpi(Auto.Farbe,{'red','yellow','green'});
Farbe = M(X,:);
Or else download this:
and use it something like this:
[~,Farbe] = colornames('CSS',Auto.Farbe)

Steven Lord
Steven Lord il 12 Gen 2021
Do you want your users to select colors by name or by appearance? If the latter use uisetcolor.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by