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

조회 수: 10 (최근 30일)
tcg22
tcg22 2019년 10월 3일
댓글: william Eisner 2022년 5월 16일
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
william Eisner 2022년 5월 16일
Same here. cut and past on an empty page. I cleared sort and problem went away.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jess Lovering
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
tcg22
tcg22 2019년 10월 3일
Thanks. I might try unistalling and reinstalling and see if that does anything.
Walter Roberson
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 CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by