Need help displaying the matrix in Conway's game of life

조회 수: 3 (최근 30일)
Joe Sheppard
Joe Sheppard 2018년 2월 5일
댓글: Joe Sheppard 2018년 2월 5일
So I cannot find a good way to display and then update the checkerboard during consecutive iterations of the game of life.
I am currently using mat2gray() to convert the matrix to grayscale, and then imshow() to display the matrix. But doing it this way slows down my laptop quite a lot, and I have to close and reopen the image with each iteration.
Is there a way to keep the existing matrix open (perhaps not as an image file) and update it live?
Many thanks,
Joe

답변 (1개)

Stephen23
Stephen23 2018년 2월 5일
"Is there a way to keep the existing matrix open (perhaps not as an image file) and update it live?"
Create the image as a matrix, and display it using image. Make sure that you obtain the image handle:
imh = image(M);
then simply update the image handle's data whenever you want:
set(imh,'CData',M)
Read more in the MATLAB documentation:
  댓글 수: 2
Guillaume
Guillaume 2018년 2월 5일
Assuming the matrix is just 0s and 1s, I recommend using
imh = image(M, 'CdataMapping', 'scaled')
colormap gray
Joe Sheppard
Joe Sheppard 2018년 2월 5일
I will try this, as Stephens suggestions just gave a uniform purple square.
Many thanks to both of you though, for getting back to me so quickly :)
I do appreciate it!

댓글을 달려면 로그인하십시오.

카테고리

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