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 visualizaciones (últimos 30 días)
How to write y(n)=y(n-1)+x(n) in a way to store all values of y from n=1 to n?

Respuesta aceptada

James Tursa
James Tursa el 20 de Abr. de 2017
Editada: James Tursa el 20 de Abr. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by