With a given matrix A (size m x n) create a matrix B (size m+2 x n+2) so that the matrix A is surrounded by ones:

A = [1 2 3
     3 2 1]
B = [1 1 1 1 1
     1 1 2 3 1
     1 3 2 1 1
     1 1 1 1 1]

or

A = 4
B = [ 1 1 1
      1 4 1
      1 1 1]

Solution Stats

3989 Solutions

1454 Solvers

Last Solution submitted on Apr 12, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Group


Problem Recent Solvers1454

Problem Tags

Community Treasure Hunt

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

Start Hunting!