필터 지우기
필터 지우기

error when sum a vector

조회 수: 1 (최근 30일)
Sahar abdalah
Sahar abdalah 2015년 5월 6일
댓글: Jos (10584) 2015년 5월 6일
hello, I want to sum a vector but I have this error
probabilite= [0.165575031104594 0.158621930989492 0.160414724735035 0.159513234647443 0.159438658281726];
somme=sum( probabilite)
error :
Subscript indices must either be real positive integers or logicals.
Error in Untitled (line 6)
somme=sum( probabilite)
please help me, how can correct this error?

채택된 답변

Purushottama Rao
Purushottama Rao 2015년 5월 6일
It did not gave any error in my pc.
>> probabilite= [0.165575031104594 0.158621930989492 0.160414724735035 0.159513234647443 0.159438658281726];
somme=sum( probabilite)
somme =
0.8036
  댓글 수: 4
Sahar abdalah
Sahar abdalah 2015년 5월 6일
I closed matlaband I open it again and it works now thank you
Jos (10584)
Jos (10584) 2015년 5월 6일
Good luck closing and re-opening matlab all the time! :-)

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

추가 답변 (1개)

Jos (10584)
Jos (10584) 2015년 5월 6일
편집: Jos (10584) 2015년 5월 6일
Most likely you have declared a variable called sum, which now clashes with the function sum
In your case, you then want to index the 0.165575031104594th and other values of the variable array sum, which is nonsense, of course, causing MatLab to throw an error.
What does
whos ('sum')
return?
However, these bugs can be nasty and not so easy to spot:
sum = [1 2 3]
p = [2 3]
answer = sum(p)
Lesson to be learned : do not name your variable after a function, but be more descriptive, using names like sumA or sumData.
(btw the solution is to clear the variable sum, which shouldn't have been created by you in the first place)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by