Make a rainbow matrix (follow-up to checkerboard matrix) - MATLAB Cody - MATLAB Central

Problem 44063. Make a rainbow matrix (follow-up to checkerboard matrix)

Difficulty:Rate

Given an integer n, make an n-by-n matrix as shown below. The a(1,1) should be 0. As we move away from the top-left, the number increase by 1, until we hit a diagonal, where all the elements are (n-1) along the diagonal. After passing diagonal, the number increases by 1 each time.

This is a follow-up question to Cody Challenge CheckerBoard Problem at https://www.mathworks.com/matlabcentral/cody/problems/4-make-a-checkerboard-matrix

For n=10

 Input  n = 10
 Output a is
  [0   1   2   3   4   5   6   7   8   9
   1   2   3   4   5   6   7   8   9   8
   2   3   4   5   6   7   8   9   8   7
   3   4   5   6   7   8   9   8   7   6
   4   5   6   7   8   9   8   7   6   5
   5   6   7   8   9   8   7   6   5   4
   6   7   8   9   8   7   6   5   4   3
   7   8   9   8   7   6   5   4   3   2
   8   9   8   7   6   5   4   3   2   1
   9   8   7   6   5   4   3   2   1   0]

Solution Stats

57.89% Correct | 42.11% Incorrect
Last Solution submitted on Mar 03, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
2
4
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

Matrix Patterns III Image
Matrix Patterns III
  • 12 Problems
  • 47 Finishers

Problem Recent Solvers71

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page