MATLAB Answers

Matlab gives error on empty line

조회 수: 2(최근 30일)
BBB
BBB 2021년 5월 13일
댓글: Tushal Desai 2021년 5월 14일
Hi! I was writing a code for an exercise but i was keep getting the same error on the same line as
"Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform
elementwise matrix powers, use '.^'."
i dont even have "^" symbol on that line and i delete the whole line even though it gives the same error and when i click "line 51" it opens a new window called mpower and shows 51th line which again with no "^" symbol.
Can you help me with this?
  댓글 수: 1
Rik
Rik 2021년 5월 14일
Most symbols in Matlab will call a function internally: + will call plus, - will call minus, etc. So when you see ^, that will call mpower. Because most people will use ^ instead of directly calling mpower, the error message contains the symbol instead.
Walter already answered your question. If it solved your issue, you should accept his answer. If not, feel free to post follow-up questions in a comment to either this question, or his answer.

댓글을 달려면 로그인하십시오.

답변(1개)

Walter Roberson
Walter Roberson 2021년 5월 13일
The important part is Untitled line 43, which is the assignment to K_fc .
On that line you have three places where you have expressions ^2 . At least one of the expressions is resulting in something that is not a square matrix. For example eta might be a row vector. When you want to square a vector you need to use .^ instead of ^
If you are working with vectors, then chances are high that you need to be using ./ instead of / . You might well also be needing to use .* instead of * on the line.
  댓글 수: 7
Tushal Desai
Tushal Desai 2021년 5월 14일
Thank you for confirming and sorry for the inconvenience.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by