how to insert RGB percentage colors in a vector?
11 views (last 30 days)
Show older comments
nick Luyten
on 12 Dec 2014
Commented: nick Luyten
on 15 Dec 2014
Hello, I wrote a code that produces polynomiographic drawings of input polynomials I put all the colors in a vector that are coded with a letter but i want more colors so i can input polynomials of higher grades but nothing seems to work. here is the code i have
function [ y ] = polyn( f,df,c)
nulpt=roots(c);
k=['r' 'y' 'b' 'g' 'm' 'c' 'w' 'k'];
d=numel(nulpt);
for a=(-1.5:10^(-2):1.5)
for b=(-1.5:10^(-2):1.5)
x=a+b*1i;
y=newton(f,df,x);
for l=1:d
if abs(y-nulpt(l))<10^(-2)
plot(a,b,'.', 'Color', k(l))
hold on
end
end
end
end
end
this works fine but i want more colors in k i have tried naming a color like r=[1 1 1] or just put the vector in k but nothing seems to work
0 Comments
Accepted Answer
Image Analyst
on 12 Dec 2014
Edited: Image Analyst
on 12 Dec 2014
You have to make k an N by 3 colormap (array). So if you want certain specific non-standard colors, you can't use letters anymore -- you need 3 numbers.
k = [...
1,0,0
1,1,0
0,0,1
0,1,0
1,0,1
etc....
plot(a,b,'.', 'Color', k(l, :));
2 Comments
Image Analyst
on 12 Dec 2014
You're welcome. Actually you can mix arrays and letters if you use cell arrays, like Guillaume showed. Cell arrays are more complicated and confusing but sometimes necessary. Read the FAQ if you want to get a good feeling for how to use them: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
More Answers (3)
Guillaume
on 12 Dec 2014
As defined, your k is just:
k = 'rybgmcwk';
since a matrix of characters is just a string.
You can solve your problem, by either
1. Putting your colours in a cell array. That way you can mix colour strings and RGB values
k = {'r' 'y' 'b' 'g' 'm' 'c' 'w' 'k' [1 .2 .5] [.3 .6 .9]}; %for example
assert(numel(k) >= d); %otherwise you've got a problem
%...
plot(a, b, '.', 'Color', k{l});
2. Putting your colours in a d*3 matrix. You can only have RGB values
k = [1 1 1
0 1 1
1 0 0
0.2 0.4 0.6]; %for example
assert(size(k, 1) >= d); %otherwise you've got a problem
%...
plot(a, b, '.', 'Color', k(l, :));
3. Change the ColorOrder property of the axes and not bother specifying colours in your plot:
k = [1 1 1
0 1 1
1 0 0
0.2 0.4 0.6]; %for example
assert(size(k, 1) >= d); %otherwise you've got a problem
haxes = gca;
haxes.ColorOrder = k; %use set pre-R2014b
hold on
%...
plot(a, b, '.');
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!