Adding a frame of zeros to a matrix

조회 수: 4 (최근 30일)
Rashid Hussein
Rashid Hussein 2019년 4월 4일
댓글: Guillaume 2019년 4월 4일
I have a matrix 19x9 I want to add a frame of zeros so I will be 20x10 ?????

채택된 답변

Guillaume
Guillaume 2019년 4월 4일
Not sure which corner you want to pad with zeros. I'm assuming bottom right:
newmatrix = [yourmatrix, zeros(size(yourmatrix, 1), 1); zeros(1, size(yourmatrix, 2) + 1)];
If you have the image processing toolbox:
newmatrix = padarray(yourmatrix, [1 1], 'direction', 'post');
  댓글 수: 2
Rashid Hussein
Rashid Hussein 2019년 4월 4일
Actually I want to add the zeros as frame for all corners So the original matrix would be surrendered by zeros like square
Guillaume
Guillaume 2019년 4월 4일
newmatrix = [zeros(1, size(yourmatrix, 2) + 2); zeros(size(yourmatrix, 1), 1), yourmatrix, zeros(size(yourmatrix, 1), 1); zeros(1, size(yourmatrix, 2) + 2)];
Using padarray:
newmatrix = padarray(yourmatrix, [1 1]);

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by