How can I use RGB value?

5 views (last 30 days)
Artem
Artem on 27 Oct 2012
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.

Answers (1)

Walter Roberson
Walter Roberson on 27 Oct 2012
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 Comments
Artem
Artem on 27 Oct 2012
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 on 27 Oct 2012
Change popumenu to popupmenu

Sign in to comment.

Categories

Find more on Simulink Environment Customization 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!