I want to add a 20 by 20 matrix to a 50 by 50 matrix ? the resuting matrix should be of 50 by 50 .

For Example : A=5*ones(50) & B=2*ones(20) , how should A+B be evaluated ?

댓글 수: 3

You tell us how it should be evaluated since it makes no sense mathematically.
Possibly you want to pad the smaller matrix with 0, only you knows.
Mr. Raghavendra did right what i wanted ! But ur question was also in my mind to pad zeros with the smaller matrix. How would u do it
Exactly, the way Raghavendra did it, or using padarray if you have the imaging toolbox.

댓글을 달려면 로그인하십시오.

 채택된 답변

추가 답변 (1개)

For arbitrary sized 2D matrices A and B:
% example data
A = ones(3,5)
B = 2*ones(4,2)
% engine
szA = size(A)
szB = size(B)
C = zeros(max([szA ; szB]))
C(1:szA(1),1:szA(2)) = A
C(1:szB(1),1:szB(2)) = C(1:szB(1),1:szB(2)) + B

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2015년 2월 26일

답변:

2015년 2월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by