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

조회 수: 29 (최근 30일)
ammara khurshid
ammara khurshid 2017년 11월 27일
댓글: ammara khurshid 2017년 12월 2일
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
ammara khurshid
ammara khurshid 2017년 11월 27일
편집: ammara khurshid 2017년 11월 27일
I want size(newA)=size(B) but this way it becomes size(newA)>size(B). kindly urgent help needed.

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

채택된 답변

Guillaume
Guillaume 2017년 11월 27일
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.

추가 답변 (1개)

James Tursa
James Tursa 2017년 11월 27일
Another way:
newA = zeros(size(B));
newA(1:size(A,1),1:size(A,2)) = A;
  댓글 수: 2
Guillaume
Guillaume 2017년 11월 27일
Yes, actually simpler than my answer. And in case A is not of class double:
newA = zeros(size(B), 'like', A);

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by