Colors in Matlab as a vriable

5 ビュー (過去 30 日間)
Rao Maaz Bin Khalid
Rao Maaz Bin Khalid 2021 年 1 月 12 日
回答済み: Steven Lord 2021 年 1 月 12 日
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.

回答 (2 件)

Stephen23
Stephen23 2021 年 1 月 12 日
編集済み: Stephen23 2021 年 1 月 12 日
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 2021 年 1 月 12 日
Do you want your users to select colors by name or by appearance? If the latter use uisetcolor.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by