Sum of empty matrix
Show older comments
The sum of an empty matrix does not always follow the rule 'sum(empty) = 0'. What's up with this?
>> sum(ones(1,0))
ans = 0
>> sum(ones(0,1),2)
ans = Empty matrix: 0-by-1
>> sum(ones(2,0))
ans = Empty matrix: 1-by-0
>> sum(ones(0,2),2)
ans = Empty matrix: 0-by-1
Answers (2)
the cyclist
on 30 Mar 2012
0 votes
I don't think this answers your question, but it does give some related info: http://blogs.mathworks.com/loren/2009/11/04/calculus-with-empty-arrays/
Jan
on 30 Mar 2012
Especially:
sum(ones(1, 0)) % 0
sum(ones(2, 0)) % Empty matrix: 1-by-0
is not intuitive anymore. Please contact the technical support and ask for an enhancement.
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!