how to insert RGB percentage colors in a vector?

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

 Réponse acceptée

Image Analyst
Image Analyst le 12 Déc 2014
Modifié(e) : Image Analyst le 12 Déc 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 commentaires

nick Luyten
nick Luyten le 12 Déc 2014
thanks for youre time and efford. This really is a big help :D
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

Connectez-vous pour commenter.

Plus de réponses (3)

Guillaume
Guillaume le 12 Déc 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, '.');

1 commentaire

nick Luyten
nick Luyten le 15 Déc 2014
Thanks verry much. I ended up using your first solution

Connectez-vous pour commenter.

Thorsten
Thorsten le 12 Déc 2014
Modifié(e) : Thorsten le 12 Déc 2014
To get, e.g,, 10 different colors, you can define your colormap like
cm = jet(10);
cm = distinguishable_colors(10);
and then plot
hold on, for i = 1:10, plot(rand(1, 20), 'Color', cm(i,:)), end
nick Luyten
nick Luyten le 12 Déc 2014

0 votes

Thank you verry much all for your time and effort. It was a great help

Catégories

En savoir plus sur Images dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by