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

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 个评论

Same here. cut and past on an empty page. I cleared sort and problem went away.

请先登录,再进行评论。

回答(1 个)

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 个评论

Nope. The entirety of the code is what I posted.
Strange. I copied the lines into my matlab and it worked fine. Good luck!
Thanks. I might try unistalling and reinstalling and see if that does anything.
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.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

产品

版本

R2019b

标签

提问:

2019-10-3

Community Treasure Hunt

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

Start Hunting!

Translated by