I want to add a 20 by 20 matrix to a 50 by 50 matrix ? the resuting matrix should be of 50 by 50 .
1 次查看(过去 30 天)
显示 更早的评论
For Example : A=5*ones(50) & B=2*ones(20) , how should A+B be evaluated ?
3 个评论
采纳的回答
更多回答(1 个)
Jos (10584)
2015-2-26
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!