MATLAB: Am trying to reduce a vector by summing some elements in the vector to form another vecter

min

example if v=[40,34,10,8,6,2] then the new vector will make 40 to be the reference point. after comparing each element the new vector will be N=[40,34,26]

Best Answer

b = cumsum(hankel(v));
k = max(b .* (b <= 40));
N = k(cumsum(k) <= b(end,1));
or
t = cumsum(hankel(v));
t = max(t.*(t <= 40));
N = t(cumsum(t) <= sum(v));