Construct a matrix whose elements begin from 1 and end at n^2 with the order of arrangement as shown below:
For:
n = 4
output
M = [1 2 6 7; 3 5 8 13; 4 9 12 14; 10 11 15 16]
Note the elements increase and decrease along alternating diagonals with the last element being always n^2.
Solution Stats
Problem Comments
1 Comment
Solution Comments
Show comments
Loading...
Problem Recent Solvers93
Suggested Problems
-
Find the longest sequence of 1's in a binary sequence.
6813 Solvers
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
2056 Solvers
-
What is the distance from point P(x,y) to the line Ax + By + C = 0?
560 Solvers
-
Sum the entries of each column of a matrix which satisfy a logical condition.
176 Solvers
-
355 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Additional test cases have been added.