magic
Magic square — square matrix where every row, column, and diagonal sums to the same value.
Syntax
Section titled “Syntax”M = magic(n)Description
Section titled “Description”Returns an n×n matrix of the integers 1:n^2 arranged so that every row, every column, and both main diagonals share the same sum. n must be a positive integer. Often used as test data because the structure is unambiguous.
Examples
Section titled “Examples”magic(3) % [8 1 6; 3 5 7; 4 9 2]sum(magic(5)) % uniform column sumssum(magic(5), 2) % uniform row sums