%==========================================================================
%
% Description: This is example code for how to create a custom colormap in 
%               matlab
%
% Author: C. Alex Simpkins
%
% Date: Tues Oct 17, 2006
%
%
%==========================================================================

%close any previous figures...
close all


%first let's generate some data to plot using the built-in matlab function
%peaks(), then store it in the matrix X

X=peaks(50);

%using a built-in colormap of matlab, let's plot the surface with the
%pcolor command
figure(1);
pcolor(X);
colormap(hot);
shading interp;


%now that's interesting, but perhaps we're only interested in the peaks
%(upper and lower) and nothing in between. Well let's design a custom color
%map which will highlight those features...

%Let's create another figure
%because matlab only lets us plot using one colormap per figure
figure(2);

%then let's create the colormap and graph each color component (R, G, B)

%We allocate the space in memory (makes it execute faster in matlab)
reds = zeros(1,1001);
greens = reds;
blues = zeros(1,1001);

%compute the input array for the equation...
number=0:10/1000:10;


%compute the reds and greens using an exponentially growing and decaying
%function, respectively...
reds=exp(-number); 
greens = exp(number);

%scale the exponentially growing number so it is in the range 0 to 1
greens=greens/max(greens); 

%store the red, green and blue components as an nx3 matrix...
my_map = [reds' greens' blues' ]; 

%plot our colormap as the three lines of red, green and blue components...
plot(reds,'r*'); hold on;
plot(greens,'g*');
plot(blues,'b*');


%and let's now apply the new colormap to the figure(1) plot...
figure(3);
pcolor(X);
colormap(my_map);
shading interp;
