function cmap = stoplight(n)
% STOPLIGHT - returns a colormap array with stop light colors (r, y, g)
%
% generates an Nx3 array of the RGB values of a colormap that ranges from
% red at the low end, yellow in the middle, and green at the high end.
%
% USAGE
% cmap = stoplight(n)
%
% INPUTS
% n - (optional) the number of bins in the colormap. Default is 64.
%
% OUTPUTS
% cmap - the Nx3 colormap that can be used with the 'colormap' command
%
% James Roberts
% 02/03/2011
% check the inputs
if nargin == 0
n = 64;
elseif nargin > 1
error('too many inputs')
elseif ~isinteger(n) || n <=3
error('input must be an integer greater than 3')
end
% set the x, y, and z valules and interpolate
x = [1,ceil(n/2),n];
xnew = 1:n;
y = 1:3;
ynew = 1:3;
[x,y] = meshgrid(x,y);
[xnew,ynew] = meshgrid(xnew,ynew);
z(:,1) = [1 0 0]';
z(:,2) = [1 1 0]';
z(:,3) = [0 1 0]';
cmap = interp2(x,y,z,xnew,ynew)';