Colors in Matlab as a vriable

8 views (last 30 days)
Rao Maaz Bin Khalid
Rao Maaz Bin Khalid on 12 Jan 2021
Answered: Steven Lord on 12 Jan 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.

Answers (2)

Stephen23
Stephen23 on 12 Jan 2021
Edited: Stephen23 on 12 Jan 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 on 12 Jan 2021
Do you want your users to select colors by name or by appearance? If the latter use uisetcolor.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!