MATLAB: How to change values in an array based upon its previous value

for loopiterationMATLABmatrix arrayzeros

Hi all! I'm new to MATLAB.
So basically I have a 2D array and a spreading pattern/fractal that I wish to execute, I can make the pattern happen when turning zeros to ones but then it get's messy after that. the image is a basic rundown of what I want to happen for each iteration of the pattern.
Thank you, Michael.Pattern MATLAB.PNG

Best Answer

Assuming you've made a mistake in your second step (see comment), this is trivially achieved with imdilate (requires image processing toolbox
A = [0 0 0 0 0; 0 0 0 0 0;0 0 1 0 0; 0 0 0 0 0; 0 0 0 0 0]
nstep = 5;
for step = 1:nstep
A = imdilate(A > 0, [0 1 0; 1 1 1;0 1 0]) + A
end