Problem 364. Matrix spiral
Make a spiral in a (n*n) matrix. The spiral has to start in the top left, and has to rotate clockwise to the center. The spiral has to have a padding of zeros between itself.
The (n*n) matrix is filled with zeros except for the spiral, that has to be made of 11 (elevens, for visual reference). The final matrix has to have the same or more zeros than elevens.
Example: n=8
A =
11 11 11 11 11 11 11 11 0 0 0 0 0 0 0 11 0 0 11 11 11 11 0 11 0 0 11 0 0 11 0 11 0 0 11 0 11 11 0 11 0 0 11 0 0 0 0 11 0 0 11 11 11 11 11 11 0 0 0 0 0 0 0 0
Solution Stats
Problem Comments
-
3 Comments
This one took me a while :)
Why are there 0's on the bottom row, and two columns of 0's on the left hand side?
@Brandon the matrix has to be square, and, according to the problem statement, "has to have the same or more zeros than elevens". If you used e.g. A(1:end-1, 2:end) of the given A, (for n = 8), you'd fail the latter condition.
Solution Comments
Show commentsProblem Recent Solvers83
Suggested Problems
-
Determine whether a vector is monotonically increasing
20756 Solvers
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15529 Solvers
-
Similar Triangles - find the height of the tree
300 Solvers
-
409 Solvers
-
Decimation - Optimized for speed
170 Solvers
More from this Author1
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!