Clear Filters
Clear Filters

How can I do this matrix ?

1 view (last 30 days)
zeezo
zeezo on 20 Feb 2018
Commented: zeezo on 21 Feb 2018
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 ?

Accepted Answer

Stephen23
Stephen23 on 20 Feb 2018
Edited: Stephen23 on 20 Feb 2018
>> 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
  4 Comments
zeezo
zeezo on 21 Feb 2018
Thanks a lot

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!