Why does sum([]) equal to zero?
조회 수: 3 (최근 30일)
이전 댓글 표시
Executing the following gives zero as the result.
sum([])
I expect an error or an empty matrix as the answer.
채택된 답변
MathWorks Support Team
2009년 6월 27일
A fundamental property of the SUM function is that if A and B are sets of numbers, then
sum(union(A, B)) = sum(A) + sum(B)
In order to maintain this property, a number must be returned for empty matrices. Thus the number 0 is returned for empty matrix inputs to the SUM function.
Note: the 'union' operation referred to above is a mathematical definition, different from the UNION function in MATLAB.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Identification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!