MATLAB: Matrix with Bell Triangle

MATLABmatrix manipulation

I need to reshape a portion of a matrix computed with the values of a bell triangle where n is the number of rows of a matrix. How can I generate a matrix contain the bell values? I mean, as an example, for n= 4 but could be any value:
1
1 2
2 3 5
5 7 10 15
empty space with 0.

Best Answer

Simple. Just use loops.
n = 5;
BellTri = zeros(n);
BellTri(1,1) = 1;
for i = 2:n
BellTri(i,1) = BellTri(i-1,i-1);
for j = 2:i
BellTri(i,j) = BellTri(i - 1,j-1) + BellTri(i,j-1);
end
end
BellTri
BellTri =
1 0 0 0 0
1 2 0 0 0
2 3 5 0 0
5 7 10 15 0
15 20 27 37 52