Matlab: Colorspectrum

Colorspectra with Matlab

(German) This post is about a Matlab-function, to generate colorspectras for multiple plots. Therefor you can change the colorsweep in different way.
This is the function (Download):

function [CoolSpec] = ColSpec(a,q,value,start)

On can define with "a" the amount of different colors in the area between red over yellow to green to blue to pink and further to red. q displays the q'th value of the generated spectra. With "value" the width of the spectra is described wherefor value>1 decreases the spectrawidth. "start" is the startingvalue for the color. Therefor red is (start = 0), yellow (start = 0.5), green(start = 1), brightblue (start = 1.5-2), darkblue(start = 2.5) and pink (start = 3) and the again red and so on.

With "m" and "k" is the darkness for values smaller 1. "inv" inverte the colorspec for values unequal zero from blue over green to red.

Here a different parameters shown as an example:




Quellcode:

function [CoolSpec] = ColSpec(a,q,value,start,m,k,inv)
% This Function creates a colorsweep for mulitple plots.
%Therefor "a" defines the amount of different colors
% "q" ist the qth value which is created
% "value" defines how far the sweep should be. So for value = 1
% the sweep goes form red to yellow to green to blue to violett.
%start is the value at which color you want to start.
%start = 0 --> red
%start = 0.5 --> yellow
%start = 1 --> green
%start = 1.5 - 2 --> brigthblue
%start = 2.5 --> darkblue
%start = 3 --> pink
%m and q handels the brigthness of th curve
%inv handels the inverted spectra from blue to red over over

if nargin <7
    inv = 0;
end
if nargin <6
    k=1;
end
if nargin <5
    m=0.9;
end
if nargin <4
    start = 0;
end
if nargin <3
    value=0.9;
end
alt = a;
a = a*value*1.2;
s = round(start*alt/3);
speed = 6;
c1=0;
c2=0;
c3=0;
for j=s:1:alt+s-1
    i=j;
    counter = j-s+1;
    if i>a;
        i = round(i-a);
    end
    if i<a/(3)
        r = 2*m-i/a*speed;
        g = i/a*speed;
        b = 0;      
    end
    if i>=a/(3) && i<2*a/(3)
        r = 0;
        g = 2*m-(i-a/(3))/a*speed;
        b = (i-a/(3))/a*speed;      
    end
    if i>=2*a/(3)
        r = (i-2*a/(3))/a*speed;
        g = 0;
        b = 2*m-(i-2*a/(3))/a*speed;      
    end
    %ROT
    if r<0
        r1 = 0;
    elseif r<1
        r1 = r;
    else
        r1=m;
    end
    %GRÜN
    if g<0
        g1 = 0;
    elseif g<1
        g1 = g;
    else
        g1=m;
    end
  
    if b<0
        b1 = 0;
    elseif b<1
        b1 = b;
    else
        b1=m;
    end
    %%%%%%%%%%%
    if r1==m
        c1 = c1+1;
        c1c(c1) = i;    
    end
    if g1==m
        c2 = c2+1;
        c2c(c2) = i;
    end
    if b1==m
        c3 = c3+1;
        c3c(c3) = i;
    end
    %%%%%%%%%%%
  
    %%%%%%%%%%%
    if inv == 0
        col = [k*r1 k*g1 k*b1];
    else
        col = [k*b1 k*g1 k*r1];
    end
    CoolSpec{j-s+1,:} = col;
    if i>alt;
        i = 0;
    end
end
if c1>2
    for i=2:1:c1
      
        if inv == 0
            CoolSpec{c1c(i),:} = CoolSpec{c1c(i),:}-[0.08*i 0 0];
        else
            CoolSpec{c1c(i),:} = CoolSpec{c1c(i),:}-[0 0 0.08*i];
        end
    end
end
if c2>2
    for i=2:1:c1
        if inv == 0
            CoolSpec{c2c(i),:} = CoolSpec{c2c(i),:}-[0 0.08*i 0];
        else
            CoolSpec{c2c(i),:} = CoolSpec{c2c(i),:}-[0 0.08*i 0];
        end
    end
end
if c3>2
    for i=2:1:c3
        if inv == 0
            CoolSpec{c3c(i),:} = CoolSpec{c3c(i),:}-[0 0 0.08*i];
        else
            CoolSpec{c3c(i),:} = CoolSpec{c3c(i),:}-[0.08*i 0 0];
        end
    end
end


if nargin > 1
    CoolSpec = CoolSpec{q,:};
end

Kommentare

Beliebte Posts aus diesem Blog

Matlab: Point on ellipsoidal surface

Matlab: Segmentation Growing

Matlab: Dijkstra methode - shortest way on gradient (small neighborhood)