how to insert RGB percentage colors in a vector?
Ältere Kommentare anzeigen
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
Akzeptierte Antwort
Weitere Antworten (3)
Guillaume
am 12 Dez. 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 Kommentar
nick Luyten
am 15 Dez. 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
am 12 Dez. 2014
0 Stimmen
Kategorien
Mehr zu Images finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!