i am executing this piece of code and getting this error" Subscript indices must either be real positive integers or logicals" how to solve it
1 view (last 30 days)
Show older comments
X=[63 -34 49 10 7 13 -12 7; -31 23 14 -13 3 4 6 -1; 15 14 3 -12 5 -7 3 9; -9 -7 -14 8 4 -2 3 2; -5 9 -1 47 4 6 -2 2; 3 0 -3 2 3 -2 0 4; 2 -3 6 -4 3 6 3 6; 5 11 5 6 0 3 -4 4];
X0=X; Y0=max(X);
0 Comments
Accepted Answer
Stephen23
on 3 Mar 2015
Edited: Stephen23
on 3 Mar 2015
When I run your code I don't get any error at all. And actually there is nothing wrong with this code.
You are getting this error because you have defined a variable with the name max, and then the code max(X) makes MATLAB think that you want to index into it. We can demonstrate this quite easily:
>> X=[63 -34 49 10 7 13 -12 7; -31 23 14 -13 3 4 6 -1; 15 14 3 -12 5 -7 3 9; -9 -7 -14 8 4 -2 3 2; -5 9 -1 47 4 6 -2 2; 3 0 -3 2 3 -2 0 4; 2 -3 6 -4 3 6 3 6; 5 11 5 6 0 3 -4 4];
>> X0=X; Y0=max(X);
Which works without any error. But when we assign a variable to max, we get the error:
>> max = 1:3;
>> X0=X; Y0=max(X);
Subscript indices must either be real positive integers or logicals.
So you need to find where you define this variable to the name max, and change the name. You can also clear variables from the workspace using clear all. or clear max.
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!