Putting 1 around the matrix

1 次查看(过去 30 天)
Hi I have a 3X3 matrix and want to put 1 around the matrix as it will become 4X4 matrix.....
  3 个评论
Offroad Jeep
Offroad Jeep 2016-9-23
yes I need 3X3 matrix Converted to 5X5 by putting 1 all around

请先登录,再进行评论。

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-9-23
Let A - your matrix [3 x 3]:
A = magic(3);
out = ones(2 + size(A));
out(2:end-1,2:end-1) = A;

更多回答(1 个)

Adam
Adam 2016-9-23
编辑:Adam 2016-9-23
a = zeros(3);
b = padarray( a, [1 1], 1 );
would put 1s all the way round, but this produces a 5x5 matrix. A 4x4 matrix result is ambiguous without being more clearly defined.
Note: This requires the Image Processing Toolbox though

类别

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