Check whether the input matrix is a normal magic square:
Output the logical value true or false.
Solution Stats
Problem Comments
8 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers301
Suggested Problems
-
Replace NaNs with the number that appears to its left in the row.
3074 Solvers
-
All your base are belong to us
582 Solvers
-
1513 Solvers
-
675 Solvers
-
07 - Common functions and indexing 2
423 Solvers
More from this Author23
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
This could be improved with a better test suite. For example, flipud(magic(n)) is still magical, but most of the leading solutions would return false for this.
Yes, test suite is substandard. Could have drawn from this: http://nrich.maths.org/1338
Why is magic(2) not a magic square ?
I was not notified about some of the older comments, so was unaware of some of the weaknesses of the test suite, and the "gamed" solutions. I have substantially improved the test suite.
The MATLAB command magic(2), although it does produce output, is not a magic square, according to the definition. (There is no 2x2 magic square.)
Test cases have been added to the problem.
why is ones(2) not a magic square ?
@VBBV It is a magic square, but the problem is asking about normal magic squares, which Wikipedia defines as containing precisely the numbers 1 to n^2 (for some n). ones(2) is not a normal magic square.