MATLAB: How to create an array of the form [1,2,4,7,11,16] without the use of a loop

array

Is is possible to create a Matlab array where the jump between two consecutive numbers is not constant but increases by 1 every time?

Best Answer

It is, using the cumsum function (and a bit of fudging to get the result you want):
x = 1:5;
xs = [1 1+cumsum(x)]
xs =
1 2 4 7 11 16