MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

You are given a matrix full of numbers who happen to be very shy. Write a MATLAB function that will put a square of zeros around each term in the matrix, thus giving them the privacy and space they desire. This should include a border of zeros around the outside of the matrix.

For example, if your input matrix is magic(3):

[8 1 6 3 5 7 4 9 2]

your output will be:

[0 0 0 0 0 0 0 0 8 0 1 0 6 0 0 0 0 0 0 0 0 0 3 0 5 0 7 0 0 0 0 0 0 0 0 0 4 0 9 0 2 0 0 0 0 0 0 0 0]

Please help them out, but do so quietly; they don't like the attention very much.

48 correct solutions
27 incorrect solutions

Last solution submitted on Jul 11, 2015

4 players like this problem

2 players like this solution

2 Comments

J.R.! Menzinger
on 19 Dec 2013

Always a chance to learn new matlab functions.

bainhome
on 31 May 2015

"find" combine with "accumarray" function so naturally,couldn't even tell which is which.really good work!

2 Comments