sum function not working

조회 수: 7 (최근 30일)
Anthony
Anthony 2013년 9월 11일
댓글: Osama 2023년 2월 27일
when I enter:
sum([1 2 3])
i get the error message: Index exceeds matrix dimensions.
This seems like a bug.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 9월 11일
편집: Azzi Abdelmalek 2013년 9월 11일
You've probably used sum as a variable. Check in your code, you will find that sum was used as a variable. Clear the variable sum then use again the sum function
clear sum
sum([1 2 3])
  댓글 수: 1
Osama
Osama 2023년 2월 27일
Thanks a lot for this

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

추가 답변 (2개)

Jan
Jan 2013년 9월 12일
편집: Jan 2017년 1월 30일
Dear Anthony,
How likely do you think is a bug in such a fundamental Matlab function? We have 96'559 participators in this forum currently and 7447 people have published functions in the FileExchange. Therefore I'm convinced, that there are at least 100'000 Matlab users (an extremely pessimistic estimation). During the development and testing of Matlab such a bug would have been found and if not, any of the users had reported it already.
Azzi's idea is most likely correct and "sum" is one of the most frequently shadowed built-in functions. But a redefined horzcat command could be the problem also.
Whenever such a magic behavior occurs, checking the user-defined parts is a good idea. It is typical, that such problems disappear magically after a restart of the computer or of Matlab. But this does not indicate, that the computer of Matlab caused the problem. It is the typical nature (or even the definition) of magic: Humen see relations between unrelated events.
Welcome to the forum have have fun with Matlab!
  댓글 수: 3
Jan
Jan 2013년 9월 12일
Yes, Anthony, peace!
Image Analyst
Image Analyst 2013년 9월 12일

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


Image Analyst
Image Analyst 2017년 1월 30일
To find out which, if any, of your m-files overload the built-in MATLAB functions, see the attached program.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by