How can I use RGB value?

5 ビュー (過去 30 日間)
Artem
Artem 2012 年 10 月 27 日
Hello! Here is my problem.
I have a code for pop-up menu:
popupmenu=uicontrol(gcf,'Style', 'popup',...
'String', 'Blue|Green|Red|Brown|Grey|Purple|Pink',...
'Position', [100 100 100 50],...
'Callback',...
['sp_col=[''b'',''g'',''r'',''W'',''W'',''W'',''m''];',...
'set(sp,''Color'',sp_col(get(popupmenu,''Value'')));',...
'sp_col=sp_col(get(popupmenu,''Value''));']);
I have RGB values:
brown = [0.5 0.25 0];
grey = [0.4,0.4,0.4];
purple=[0.5 0 0.5];
How can I use this values in my cod (instead of 'W')?
Sorry for my English.
Thank you,
Artem.

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 10 月 27 日
colors = [0 0 1; 0 1 0; 1 0 0; 0.5 0.25 0; 0.4 0.4 0.4; 0.5 0 0.5; 1 1 0];
(Note: I might have gotten the code for magenta wrong.)
Then,
'Callback', 'sp_col = colors(get(popumenu, ''Value''), :);'
  2 件のコメント
Artem
Artem 2012 年 10 月 27 日
colors = [0 0 1; 0 1 0; 1 0 0; 0.5 0.25 0; 0.4 0.4 0.4; 0.5 0 0.5; 1 1 0];
popupmenu=uicontrol(gcf,'Style', 'popup',...
'String', 'Blue|Green|Red|Brown|Grey|Purple|Pink',...
'Position', [100 100 100 50],...
'Callback', ['sp_col = colors(get(popumenu, ''Value''));','set(sp,''Color'',sp_col);']);
When I run the programm and choose some color in the menu, this error appears: Undefined function or variable 'popumenu'. Error while evaluating uicontrol Callback
Walter Roberson
Walter Roberson 2012 年 10 月 27 日
Change popumenu to popupmenu

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSimulink Environment Customization についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by