Well, if you are absolutely determined to do it in one line,
sum(vec) == subsref(cumsum(vec),struct('type','()','subs',{{numel(vec)}}))
But this is a borderline abuse of subsref
, which is generally used for overloading the subscripting operators (i.e. {}
, ()
, .
) in custom classes.