%=========================colormapdemo.m===============================
%   Demonstration of creating a custom colormap and using meshgrid...
%
%
%   Author : C. Alex Simpkins
%
%   Date: Oct 18, 2007
%
%   Subject: UCSD CogSci109, Modeling and Data Analysis
%
%   This code will demonstrate how to take a matrix of data, 
%   and create a custom colormap to map the data to.  It will also
%   demonstrate how to use the meshgrid command to scale axes
%   appropriately.
%
%   Inputs: occasional pressing of 'return' key from user to advance code
%
%   Outputs: various figures and colormaps, one custom colormap stored in
%   the variable 'c'
%======================================================================   

%generate the data...
z=peaks;

%create a pcolor plot of the data
pcolor(z);
pause
shading interp;pause
%use a built-in colormap

%this applies a colormap...
colormap bone

%this displays text on the command line (in the command window)...
disp('Using matlab colormap "bone"')

%this pauses execution at this point until the user presses enter or
%return...
pause

%this repeats the above commands but with a different colormap...
colormap hot
disp('Using matlab colormap "hot"')
pause 

%this repeats the above commands but with a different colormap...
colormap cool
disp('Using matlab colormap "cool"')
pause

%now let's make our own colormap...

%assign values to an array, and make it a column vector (ultimately we need
%3 column vectors, remember a column vector is an nx1 array of numbers...
r=0:1;
r=r'; %make r a column vector

%create zeros in the green and blue component vectors.  They have to be the
%same size as the red vector, created above...
g=zeros(size(r));
b=zeros(size(r));

%store the 3 color component vectors in one matrix that will be nx3 (n
%rows, 3 columns)...
c=[r g b];

%apply our custom colormap to our figure...
colormap(c);


%%this part is about meshgrid...

%meshgrid help...

%determine the length of z's rows...
m=length(z(:,1));

%create a variable which has a scaling from 0 to 1000, and make it the 
%length of the number of rows of z...  
x=0:1000/(m-1):1000;

%do the same for the number of columns...
n=length(z(1,:));
y=-10:(20)/(n-1):10;

%now here's the magic- use the meshgrid command to create an X and Y at
%each point of z...
[X,Y]=meshgrid(x,y);

%create a new figure window...
figure;

%and here's how we plot a 3d surface with the x and y axes scaled according
%to x and y, and we do it as a subplot because we want to compare to when 
%you don't use the meshgrid command...
subplot(2,1,1);surf(X,Y,z);

%and we label it of course...
xlabel('x')
ylabel('y')
zlabel('z')
title('Demonstration of a 3d surface plot with arbitrarily scaled x and y axes')

subplot(2,1,2); surf(z);
xlabel('x')
ylabel('y')
zlabel('z')
title('Comparison plot - note that the x and y axes are scaled\\by the indices of the location in z')





