MATLAB: How to do this matrix

matrixmatrix array

I have this Matrix
A=[1;6;9;4;2;8]
I would like to generate a matrix as follow
the first row has only 1 and the rest zeros.
the seconds row has 1 and 6 and the rest zeros
the third has 1 , 6 and 9 and the rest zeros and so one
B=
1 0 0 0 0 0
1 6 0 0 0 0
1 6 9 0 0 0
1 6 9 4 0 0
1 6 9 4 2 0
1 6 9 4 2 8
How can I do it ?

Best Answer

>> A = [1;6;9;4;2;8];
>> M = tril(repmat(A.',6,1))
M =
1 0 0 0 0 0
1 6 0 0 0 0
1 6 9 0 0 0
1 6 9 4 0 0
1 6 9 4 2 0
1 6 9 4 2 8