MATLAB: Sum of Cell Array [Besides for loop]

cell arraysum

I'm having difficulty trying to solve this problem. Suppose:
testvalue = {[1] [] []
[1] [1] [1]
[1] [] []
[1] [1] []}
I want to sum the contents of each row, which should give:
1+nil+nil=1
1+1+1=3
1+nil+nil=1
1+1+nil=1
I tried using for loop but it upon adding cumulative sum with [], the new sum becomes []. Can someone shed some light? Thanks.

Best Answer

T = testvalue;
T(cellfun(@isempty,T)) = {0};
sum( cell2mat(T), 2)