is a magic square - output = false elseif...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 % isMagicSquare(matrix) -> true/false % Description: % Tests to see if the matrix, m, is a magic square and returns the % result as a value function output = isMagicSquare(m) m = [8 1 6 3 5 7 4 9 2] for index = 1:length(m) if (sumDiagLeftToRight(m) ~= sumDiagRightToLeft(m)) disp('Not a magic square')
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: output = false elseif (sumDFiagRightToLeft(m) ~= sum(m(index,1:length(m)))) disp('Not a magic square') output = false elseif (sum(m(index,1:length(m))) ~= sum(1:length(m),index)) disp('Not a magic square') output = false else output = true end end...
View Full Document

Ask a homework question - tutors are online