Cellular Automata (CA) provide a convenient way to represent many kinds of systems in which the values of cells (either 0 or 1) in an array are updated in discrete steps according to a local rule.
Start with a single ONE at the center of the 1st row of an (n+1)-by-(2*n+1) sheet of ZEROs , the value of each point in the array at position A(i,j) , i = 2:n is determined by values of its 3-neighbors A(i-1, j-1), A(i-1,j), A(i-1,j+1) according to the given Rule.
Since we consider 3-neighbors, they can have one of 8 possible states (starting with 000 to 111). The Rule number is a decimal number between 1-256 (i.e. 2^8), where its 8-bit Bin form represents the outputs of those 8 possible states as shown in the figure below.
You problem is to generate the Cellular Automaton array given the Rule number and number of iteration to run (n = rows of array).
NOTE: you can plot the result using imagesc(CA) for fun.