Why am I getting an error trying to sort this array?
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
william Eisner
2022 年 5 月 16 日
Same here. cut and past on an empty page. I cleared sort and problem went away.
回答 (1 件)
Jess Lovering
2019 年 10 月 3 日
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 件のコメント
Walter Roberson
2019 年 10 月 4 日
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.
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!