Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- A=[0 0 0 0 0; 0 1 1 1 0; 0 0 1 1 1; 0 0 0 0 0; 0 0 0 0 0];
- %disp('Generation-0:');
- %disp(A);
- %s = size(A);
- %B = zeros(size(A));
- %n = numel(A);
- %out = cell(s);
- gen1=zeros(5,5);
- igenaration=5;
- for k=1:igenaration-1
- disp(A);
- imshow(A);
- drawnow;
- s = size(A);
- B = zeros(size(A));
- n = numel(A);
- out = cell(s);
- for i = 1:n
- B(i) = 1;
- %out{i} = A(bwdist(B,'ch') == 1);
- out{i}=A(conv2(B,[1,1,1;1,0,1;1,1,1],'same')>0);
- B(i) = 0;
- n=sum(out{i},'all');
- %n = nnz(out{i}==1);%Number of nonzero matrix elements
- %sum(out{i}(:) == 1);
- %disp(count(out{i}));
- if B(i)==1 %for current cell- live cell
- if n<2
- gen1(i)=0;
- end
- if n==2 || count==3
- gen1(i)=1;
- end
- if n>3
- gen1(i)=0;
- end
- else %for current cell- dead cell
- if n==3
- gen1(i)=1;
- end
- end
- %disp(n);
- end
- fprintf('Generation- %d:\n',k);
- %disp(gen1);
- A=gen1;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement