Explanation:
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).
Solution:
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:
MatrixMustBeSquare.m
Best Answer