声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 951|回复: 0

[编程技巧] 新手请教Demo里的Game of Life

[复制链接]
发表于 2009-3-4 23:28 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
最近在研究元胞自动机,对MATLAB一知半解。遇到个问题,下段中的N E S W 是方向向量(方括号里的是我改过的,和原来的不一样,忘了原来的是什么的了),可是不太理解这个方向向量是什么意思?有没有同志可以解释一下?并把正确的内容贴出来!我感激不尽!
% Whether cells stay alive, die, or generate new cells depends
   % upon how many of their eight possible neighbors are alive.
   % Here we generate index vectors for four of the eight neighbors.
   % We use periodic (torus) boundary conditions at the edges of the universe.
   
   n = [m 1:m-1];   e = [2:m 1];
   s = [2 1:1-m];   w = [1:1-m m];
   
   while get(axHndl,'UserData')==play,
      % How many of eight neighbors are alive.
      N = X(n,:) + X(s,:) + X(:,e) + X(:,w) + ...
         X(n,e) + X(n,w) + X(s,e) + X(s,w);

刚才找了个原始的LIFE.M,里面是这样的
n = [m 1:m-1];   e = [2:m 1];
   s = [2:m 1];   w = [m 1:m-1];
为什么E和S, N和W是一样的呢?

[ 本帖最后由 ChaChing 于 2010-6-25 21:52 编辑 ]
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-21 00:46 , Processed in 0.065338 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表