function cml(mu,E,step,map)

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

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

m=100; n=100; cont=1; t=1;
figure(1); clf;
X=zeros(m+6,n+1);
strapes=[1:n+1]./(n+1); X(m+2,:)=0;
for i=m+3:m+6 X(i,:)=strapes; end;
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)]);
clear X; 
X=rand(m+1,n+1);   % x(m-dimension, n-dimension)= Xinitial Value
imagesc(X,'Erasemode','none');
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
pause(1);
while (1)
    X=mu*X.*(1-X);                      % Iterate whole map
    X(1,:)=X(m,:);    X(m+1,:)=X(2,:);
    X(:,1)=X(:,n);    X(:,n+1)=X(:,2);  % Set border to circular space reference
    X=conv2(X,kernel,'same');           % coupling by 2-d convolution
    cont=cont+1;
    if cont>step
        cont=1;
        imagesc(X,'Erasemode','none');
        drawnow;
      % ginput(1);    %   Wait for mouse press
        title(['2D Coupled Map Lattice for mu=' num2str(mu) ' and E=' num2str(E) ' in t=' num2str(t) ]);
        name='cmla';
        if t<10 name=[name '0']; end;
        if t<100 name=[name '0']; end;
        if t<1000 name=[name '0']; end;
        if t<10000 name=[name '0']; end;
        name=[name num2str(t) '.bmp']
        imwrite(X,name);
        t=t+1;
    end
end;
