Adding a frame of zeros to a matrix

5 次查看(过去 30 天)
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