• Remix
  • Share
  • New Entry

on 21 Nov 2023
  • 13
  • 22
  • 0
  • 1
  • 256
drawframe(1);
Warning: When running MATLAB Online, InitialMagnification can only be 'fit'.
Write your drawframe function below
function drawframe(f)
rng(0)
width=50;
mag=5;
state=rand(width,width)<0.4;
figure;
h_fig=imshow(state,'InitialMagnification', mag);
shutter=ones(3,3);
for i=1:2*f
counter=conv2(state,shutter);
ctr=counter(2:width+1,2:width+1);
state=(state&(ctr==3|ctr==4))|((~state)&(ctr==3));
end
h_fig.CData=state;
end
Animation
Remix Tree