MATLAB Answers


Why do I get the error message 'Matrix must be square.' ?

Why do I get the following error message :
Matrix must be square.


No tags entered yet.


1 Answer

Answer by MathWorks Support Team on 27 Feb 2012
 Accepted Answer

You are attempting to perform an operation that is only defined for square matrices or matrices with equal number of rows and columns.
Common causes:
You are attempting to use an element-wise operator on a matrix that is nonsquare, but you are using the linear algebra operator instead of the element-wise operator. For example, you use the ^ operator (taking the power of a matrix) rather than .^ (which takes the power of each element of the matrix).
Examine the line listed in the error message and verify the matrix whose power you want to take is square, or that you are using the appropriate operator.
Example demonstrating this error:


Sign in to comment.