MATLAB: How to build a column vector looping the rows of another vector

column vector - loop

Hi all, The question is straightforward as follows: I have a column vector a(0),a(1),a(2) …a(n) from which I want to build another vector with the following definition: b(0)=a(0) b(1)=a(1)/a(0)-1+0.5% b(2)=a(2)/a(1)-1+0.5% b(3)=a(3)/a(2)-1+0.5% b(4)=a(4)/a(3)-1+0.5% etc… Can somebody help out ?
Thanks very much. Xuan Tran

Best Answer

Simply:
b = [a(1), a(2:end)./a(1:end-1)-1+0.005]
Note that using zero-based indexing in your expression is confusing when matlab is 1-based.