필터 지우기
필터 지우기

matrix sum with extending dimensions

조회 수: 2 (최근 30일)
Fangzhou Wang
Fangzhou Wang 2016년 4월 8일
편집: Azzi Abdelmalek 2016년 4월 8일
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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 8일
편집: Azzi Abdelmalek 2016년 4월 8일
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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by