you might want to make a case that's not a magic square, considering the properties of the diagonals of a magic square...
There are only magic squares in test cases, however the problem doesn't specify a type of the matrix.
You should definitely strengthen the test suite. Lots of solutions rely on both diagonals being the same, even though this is not a property of the stated problem.
The "antidiagonal" is cooler sounding than "second diagonal"
I learned about fliplr() in another problem and it is helpful here!
Thanks for the hint
I like you're use of a nested loop here.
The last test suite result should be 14.
yes ı agree
Trickey ONE indeed !!
But you can't rely on x always being a magic square - that's just an accident of the inadequate test suite, isn't it? So although this *looks* like a good solution, it isn't really. I think it's bad practice to take advantage of an inadequate test suite.
it doesn't find the sum of the elements of the second but first diagonal
Remove any row in which a NaN appears
Replicate elements in vectors
Generate a NaN...on purpose
Matlab Basics - Absolute Value
Omit columns averages from a matrix
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office