vector=sum(AllDataMat); result= 0; for k = 1:1:length(vector) if vector(k) < 0 result = result + vector(k); end end