function abm_wolfram gr_sz = 40; % grid size iterations = 19; % define initial state x = round(rand(1,gr_sz)); for it = 1:iterations % left boundary nbhd = x(it,1) + x(it,2); if ( nbhd >= 1 ) x(it+1,1) = 1; else x(it+1,1) = 0; end % interior for i = 2:(gr_sz-1) nbhd = x(it,i-1) + x(it,i) + x(it,i+1); if ( nbhd >= 1 ) x(it+1,i) = 1; else x(it+1,i) = 0; end end % right boundary nbhd = x(it,gr_sz) + x(it,gr_sz-1); if ( nbhd >= 1 ) x(it+1,gr_sz) = 1; else x(it+1,gr_sz) = 0; end 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( 1 - x ); colormap bone; % gray bone; shading flat; % flat faceted interp xlabel('grid space'); ylabel('time iterations')