Why does sum([]) equal to zero?

3 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2009 年 6 月 27 日
Executing the following gives zero as the result.
sum([])
I expect an error or an empty matrix as the answer.

採用された回答

MathWorks Support Team
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 件)

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by