Borrar filtros
Borrar filtros

matrix sum with extending dimensions

2 visualizaciones (últimos 30 días)
Fangzhou Wang
Fangzhou Wang el 8 de Abr. de 2016
Editada: Azzi Abdelmalek el 8 de Abr. de 2016
If there are two matrices like a=[1,0;0,1] b=[2,0;0,2], is there any command by which I get a 3x3 matrix as c=[1,0,0;0,3,0;0,0,2]?
I just add the last element in a with first element in b and then get a new matrix with extending dimension.
Thank you,
Rick

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 8 de Abr. de 2016
Editada: Azzi Abdelmalek el 8 de Abr. de 2016
a=[1,0;0,1]
b=[2,0;0,2]
ad=diag(a),
bd=diag(b),
dc=[ad(1:end-1) ;ad(end)+bd(1) ; bd(2:end)]
c=diag(dc)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by