MATLAB: Generate y(n)=y(n-1)+x(n)

recursive

hello i want to generate y(n)=y(n-1)+x(n). by using a for loop I can find the last value of y, but i need to store all values of y from n =1 till n. Who do I do that?

Best Answer

n=10
y0=0; % Initial conditions
y(1)=y0+x(1);
for k=2:n
y(k)=y(k-1)+x(k)
end