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 次查看(过去 30 天)
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);

采纳的回答

Stephen23
Stephen23 2015-3-3
编辑:Stephen23 2015-3-3
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by