Putting 1 around the matrix

조회 수: 4 (최근 30일)
Offroad Jeep
Offroad Jeep 2016년 9월 23일
댓글: Offroad Jeep 2016년 9월 23일
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일
ya sorry its 5X5
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
Offroad Jeep
Offroad Jeep 2016년 9월 23일
Thanks ..... worked

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

추가 답변 (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