Clear Filters
Clear Filters

Adding zeros to a matrix to match the dimensions of two matrices.

52 views (last 30 days)
Hi ! need help to match the size of two matrices. I have two matrices of dimensions mxn and jxk. I want make mxn of size jxk by adding zeros at the end of the mxn. A of mxn dimenssion and B of jxk dimenssion. Am doing by this way:
newA=[A,zeros(size(B)]
  1 Comment
ammara khurshid
ammara khurshid on 27 Nov 2017
Edited: ammara khurshid on 27 Nov 2017
I want size(newA)=size(B) but this way it becomes size(newA)>size(B). kindly urgent help needed.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 27 Nov 2017
newA = [A, zeros(size(A, 1), size(B, 2)-size(A, 2)); zeros(size(B, 1)-size(A, 1), size(B, 2))];
Assuming that both dimensions of B are greater than A.

More Answers (1)

James Tursa
James Tursa on 27 Nov 2017
Another way:
newA = zeros(size(B));
newA(1:size(A,1),1:size(A,2)) = A;

Community Treasure Hunt

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

Start Hunting!