MATLAB: Subtract values inside a array

array operationssubstraction

any help will be great. Thank you

Best Answer

MATLAB code should be beautiful, simple, and efficient:
>> V = [12;2;6;8;6;2;12];
>> 50+cumsum(-V)
ans =
38
36
30
22
16
14
2