function cml(mu,E,step,map)

% Coupled Map Lattice (mu, E, step, colormap)

% --------------------  DEFAULT VALUES -------------------------------------
if nargin<1 mu=3.9; end;           % Parameter
if nargin<2 E=.9; end;             % Coupling constant
if nargin<3 step=4; end;           % Depic Step
if nargin<4 map='default'; end;    % Alternative colormap select

% --------------------- INITIALIZE VARIABLES -------------------------------
m=100; n=100;       % Matrix Size
cont=1;             % Step Counter
X=zeros(m+6,n+1);   % X is initialy set up only to include the pallete
strapes=[1:n+1]./(n+1); X(m+2,:)=0;  % Generate the colormap pallete
for i=m+3:m+6 X(i,:)=strapes; end;   % Put the colormap in last 3 lines

% --------------------- START GRAPHICS INTERFACE----------------------------
figure(1); clf; imagesc(X,'Erasemode','none');
colormap(map); axis off; hold on; set(gca,'Drawmode','Fast');
title(['2D Coupled Map Lattice for mu=' num2str(mu) ' and E=' num2str(E)]);

% --------------------- SET UP MATRIX VALUES--------------------------------
kernel=[[E    E    E]         %   When changing kernel
        [E 8*(1-E) E]         %   don't forget to normalize
        [E    E    E]]/8;     %   x must be < 1 and > 0
clear X; X=rand(m+1,n+1);   % x(m-dimension, n-dimension)=Xi Value to Matrix

% --------------------- MAIN LOOP ------------------------------------------
imagesc(X,'Erasemode','none'); pause(1);
while (1)
    X=mu*X.*(1-X);                      % Iterate whole map at once
    X(1,:)=X(m,:);    X(m+1,:)=X(2,:);
    X(:,1)=X(:,n);    X(:,n+1)=X(:,2);  % Set border to continuous space
    X=conv2(X,kernel,'same');           % coupling by 2D convolution
    cont=cont+1;                        % with defined kernel
    if cont>step
        cont=1;
        imagesc(X,'Erasemode','none');
        drawnow;
      % ginput(1);    %   Wait for mouse press for next interaction
    end
end;
