Borrar filtros
Borrar filtros

Simple problem: Replacing a loop with a vector expression

2 visualizaciones (últimos 30 días)
C Meek
C Meek el 12 de Feb. de 2012
Editada: Jan el 29 de En. de 2023
Hi all,
I'd like to run this by people here as I can't see where I'm going wrong, despite this seeming pretty simple.
I have the following loop:
for n=M+1:N
y(n)=a*x(n)+x(n-M)-a*y(n-M);
end
I wish to implement this as a vector expression. Here is what I have got:
y(M+1:N)=a*x(M+1:N)+x(1:N-M)-a*y(1:N-M);
I'd thought this was correct, but when I do simple (or complicated) examples, the values are only the same up to a certain point. I've noticed that they are correct up to the entry that is double of the value of M (so if M=8, the outputs produced by both examples are the same up until the 16th entry in the vector).
Can anyone have a look at this and correct me if I've made a mistake? As usual it may be something simple, but I'm not seeing it!
Craig

Respuestas (1)

Jan
Jan el 12 de Feb. de 2012
  1 comentario
Jan
Jan el 29 de En. de 2023
Editada: Jan el 29 de En. de 2023
Austin Chen wrote a flag at 28 Jan 2023 at 3:22: "terrible response"
@Austin: You find an exhaustive discussion and some example code in this link.
If you know a better answer, feel free to post it.

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by