home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 3.ddi / DEMOS.DI$ / LIFELOOP.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  503 b   |  21 lines

  1. % Inner loop for life.
  2.  
  3.  %       Copyright (c) 1984-93 by The MathWorks, Inc.
  4.  
  5. while t < tfinal
  6.    t = t+1;
  7.  
  8.    % How many of eight neighbors are alive.
  9.    N = X(n,:) + X(s,:) + X(:,e) + X(:,w) + ...
  10.        X(n,e) + X(n,w) + X(s,e) + X(s,w);
  11.  
  12.    % A live cell with two live neighbors, or any cell with three
  13.    % neigbhors, is alive at the next time step.
  14.    X = (X & (N == 2)) | (N == 3);
  15.  
  16.    % Update plot.
  17.    [i,j] = find(X);
  18.    set(plothandle,'xdata',i,'ydata',j)
  19.    drawnow
  20. end
  21.