Why do I get the error message 'Matrix must be square.' ?
조회 수: 30 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2012년 2월 27일
댓글: Walter Roberson
2022년 7월 5일
Why do I get the following error message :
Matrix must be square.
채택된 답변
MathWorks Support Team
2012년 2월 27일
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
댓글 수: 1
Walter Roberson
2022년 7월 5일
[3 4]^2
is an example. It uses the matrix power operator, and would be equivalent to
[3 4] * [3 4]
but remember that the * operation is matrix multiplication (inner product), not element-by-element multiplication
A fair portion of the time when you get the message, you should probably be using the .^ operation instead of ^ . But sometimes it is just a mistake in the logic so that the array is not the square size that the programmer was expecting
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!