Create a "rainbow matrix" as described in the following examples

 Input = 3
 Output = [ 1 2 3
            2 3 2 
            3 2 1 ]
 Input = 5
 Output = [ 1 2 3 4 5
            2 3 4 5 4
            3 4 5 4 3
            4 5 4 3 2
            5 4 3 2 1 ]

Solution Stats

492 Solutions

214 Solvers

Last Solution submitted on Jun 12, 2026

Last 200 Solutions

Problem Comments

Solution Comments

Show comments
Loading...

Problem Recent Solvers214

Suggested Problems

Problem Tags

Community Treasure Hunt

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

Start Hunting!