How can I do this matrix ?

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 ?

 Respuesta aceptada

Stephen23
Stephen23 el 20 de Feb. de 2018
Editada: Stephen23 el 20 de Feb. de 2018

1 voto

>> 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 comentarios

zeezo
zeezo el 20 de Feb. de 2018
Thank you very much
zeezo
zeezo el 20 de Feb. de 2018
Now If i want to just select a small matrix from this matrix
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
just 3*3
C=
1 0 0
1 6 0
1 6 9
How Can I do it ?
Stephen23
Stephen23 el 20 de Feb. de 2018
M(1:3,1:3)
zeezo
zeezo el 21 de Feb. de 2018
Thanks a lot

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Feb. de 2018

Comentada:

el 21 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by