How to write y(n)=y(n-1)+x(n) in a way to store all values of y from n=1 to n?

5 vues (au cours des 30 derniers jours)
How to write y(n)=y(n-1)+x(n) in a way to store all values of y from n=1 to n?

Réponse acceptée

James Tursa
James Tursa le 20 Avr 2017
Modifié(e) : James Tursa le 20 Avr 2017
There are vectorized ways to do this, but using your formula directly:
y = zeros(size(x));
y(1) = something; % <-- you fill this in, e.g. maybe x(1)?
n = something; % <-- you fill this in
for k=2:n % <-- for the rest of the elements through n
y(k) = y(k-1) + x(k); % <-- your formula
end
  2 commentaires
Marwan Malaeb
Marwan Malaeb le 20 Avr 2017
Thanks, I will try it and see if it works.
Marwan Malaeb
Marwan Malaeb le 20 Avr 2017
It worked, thanks James

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by