MATLAB Answers

0

generate y(n)=y(n-1)+x(n)

Asked by Marwan Malaeb on 20 Apr 2017
Latest activity Commented on by Marwan Malaeb on 20 Apr 2017
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?

  0 Comments

Sign in to comment.

Tags

2 Answers

Azzi Abdelmalek
Answer by Azzi Abdelmalek
on 20 Apr 2017
 Accepted Answer

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

  1 Comment

that is right, thanks Azzi.

Sign in to comment.


Answer by Roger Stafford on 20 Apr 2017

That is precisely what the matlab ‘cumsum’ function does:
y = cumsum(x);

  0 Comments

Sign in to comment.