function abm_wolfram gr_sz = 100; % grid size iterations = 100; % define initial state x = round(rand(1,gr_sz)); for it = 1:iterations % interior for i = 2:(gr_sz-1) a = x(it,i-1) * 4 + x(it,i) * 2 + x(it,i+1); if ( a == 0 ) || ( a == 2 ) || ( a == 5 ) || ( a == 7 ) x(it+1,i) = 1; else x(it+1,i) = 0; end end x(it+1,1) = 1; % left boundary x(it+1,gr_sz) = 1; % right boundary end % pcolor does not plot the last row for some reason % so we copy the last row twice: x(:,gr_sz+1) = x(:,gr_sz); pcolor( x ); % surf( x ); view(0,90); %axis([ 1 gr_sz 1 iterations ]); colormap bone; % gray bone; shading flat; % flat faceted interp xlabel('grid space'); ylabel('time')