Why am I getting an error trying to sort this array?

10 visualizaciones (últimos 30 días)
tcg22
tcg22 el 3 de Oct. de 2019
Comentada: william Eisner el 16 de Mayo de 2022
I'm trying to learn Matlab and have been using code directly from the documentation to test things out. When I type the following code I get the error "Index exceeds the number of array elements (1)."
Code:
A = [9 0 -7 5 3 8 -10 4 2];
B = sort(A)
Can someone explain why this is happening?
  1 comentario
william Eisner
william Eisner el 16 de Mayo de 2022
Same here. cut and past on an empty page. I cleared sort and problem went away.

Iniciar sesión para comentar.

Respuestas (1)

Jess Lovering
Jess Lovering el 3 de Oct. de 2019
Are you using the variable name "sort" in another part of your code? This has happened to me in the past if I define a variable using the name of a function.
  4 comentarios
tcg22
tcg22 el 3 de Oct. de 2019
Thanks. I might try unistalling and reinstalling and see if that does anything.
Walter Roberson
Walter Roberson el 4 de Oct. de 2019
What shows up if you use
which -all sort
Your code might not assign to sort but at some point in the past you assigned to sort and the variable is still in your workspace.

Iniciar sesión para comentar.

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by