MATLAB Answers

0

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

Why do I get the following error message :

 
 Matrix must be square.

Tags

No tags entered yet.

Products

1 Answer

Answer by MathWorks Support Team on 27 Feb 2012
 Accepted Answer

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

  0 Comments

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today