Game of Life - Not able to collect data for each simulation

2 次查看(过去 30 天)
Hello there,
I am creating a Game of Life through Matlab (something that I am not familiar with). I have made several simulations of game of life and I need to collect data from each simulation through function of time and then plot it. This is a sample of what I did:
A = sparse(round(rand(n,m)));
B = sparse(size(A));
A = B;
subplot(2,4,1);
imagesc(A); pause(0.01);
yA = nnz(A);
subplot(2,4,5);
hold on
plot(t,yA,'r.-');
hold off
xlim([0 tmax]);
ylim auto;
pause(0.01);
But I am not able to collect any values and with this code I can plot but the points wont connect since I am planting single numbers onto the plot.
Help please and thank you.

采纳的回答

Image Analyst
Image Analyst 2016-2-28
编辑:Image Analyst 2016-2-28
Like I said in your original question before you deleted it (thank goodness for Lazarus):
"You know that yA is just a single number, right? It's the count of the number of non-zeros in A but not the actual non-zero numbers themselves."
Now, what does "collect" mean to you? A game of life will have iterations (generations or days or time periods or whatever) where you change the population. I don't see any loops where you're changing the population in any way. If you did, then you could "collect" or store each population in a 3D array. But first you need some algorithm for how you want to change the population at each iteration. Can you tell us how you plan to do that?
  4 个评论
Joe Smith
Joe Smith 2016-2-28
But I am getting an error for the plots not having the vectors being the same length
Joe Smith
Joe Smith 2016-2-28
Nevermind, fixed that as well but doing some thing
plot(G(1:t),'c-');
your presence is helping me a lot ... thank you

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Conway's Game of Life 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by