'Subscript indices must either be real positive integers or logicals' on calculating rank(A) of a numeric matrix.

조회 수: 3 (최근 30일)
Here are two errors I'm getting when using the rank function.
B = [0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 1 0 0 0 0 0; 0 1 0 0 0 0]
D = [z y x 0 0 0; y z y x 0 0; x y z y x 0; 0 x y z y x; 0 0 x y z y; 0 0 0 x y z]
rank(B)
rank(D)
For rank(B) or other numeric matrices I get:
Subscript indices must either be real positive integers or logicals.
For rank(D) or other symbolic matrices I get:
Error using sym/subsindex (line 766)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a
SYM expression. When indexing, the input must be numeric, logical, or ':'.
I've googled and tried to figure both out but am really struggling.

채택된 답변

John D'Errico
John D'Errico 2018년 3월 8일
Don't define a variable named rank, certainly not if you ever intend to use the FUNCTION named rank. This is why you get the subscript indices problem.
Similarly, when you use rank(D), MATLAB sees the result is symbolic array. But you cannot index using a symbolic variable. Again the problem is DON'T NAME A VARIABLE RANK. The same applies to variables named sum, mean, etc.
Try this:
which rank -all
What does it tell you?
  댓글 수: 3
Will Bolton
Will Bolton 2018년 3월 8일
Ok I've restarted MATLAB, suspect I unintentionally mistyped something in the command window hours ago and didn't realise. Sorry for the trouble!
John D'Errico
John D'Errico 2018년 3월 8일
You can also look in the list of workspace variables. rank would have been listed there too.
whos rank
Restarting from a clean session will make the rank variable fall into the bit bucket of course, as long as you did not save that workspace and then reload it. Just wondering though, would a rank variable smell badly? ;-) Sorry. Could not resist.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by