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

3 views (last 30 days)
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.

Accepted Answer

John D'Errico
John D'Errico on 8 Mar 2018
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 Comments
Will Bolton
Will Bolton on 8 Mar 2018
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 on 8 Mar 2018
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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!