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 visualización (últimos 30 días)
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);

Respuesta aceptada

Stephen23
Stephen23 el 3 de Mzo. de 2015
Editada: Stephen23 el 3 de Mzo. de 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.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by