Colors in Matlab as a vriable

6 Ansichten (letzte 30 Tage)
Rao Maaz Bin Khalid
Rao Maaz Bin Khalid am 12 Jan. 2021
Beantwortet: Steven Lord am 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.

Antworten (2)

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

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by