hi,
i want to write the following equation in a for loop to store values for 1000 rows..Can anyone help please?
z(k)=lamda*x(k)+(1-lamda)*z(k-1)

 Respuesta aceptada

Jan
Jan el 8 de Jul. de 2017

0 votos

z = zeros(1000, 22);
x = rand(1000, 22);
lamda = rand();
for k = 2 : 1000
z(k, :) = lamda * x(k, :) + (1-lamda) * z(k-1, :);
end

4 comentarios

Md. Tanjin Amin
Md. Tanjin Amin el 8 de Jul. de 2017
Hi, the code runs ..still the result is not satisfactory....I am attaching the data file and expected result for lamda=0.03. I have done the calculation using excell. Can you look again and help please? Thank you.
Walter Roberson
Walter Roberson el 8 de Jul. de 2017
Your expected values are wrong, not even self-consistent.
See attached code and plots.
Md. Tanjin Amin
Md. Tanjin Amin el 10 de Jul. de 2017
Hi, I am sorry. You are right the expected values were wrong. I have attached the corrected expected values. This is right this time. Can you give some time and help please?
Walter Roberson
Walter Roberson el 10 de Jul. de 2017
Your first two lines of X from X.mat are the same. That cannot be explained with any lamda other than 0 .
Your other lines of expected output cannot be explained with lamda = 0.03 : they all require lamda = 1.0003
Even then your expected outputs are frequently wrong in the 4th digit.
See attached, which is configured for 1.0003

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 8 de Jul. de 2017

0 votos

z(1) = rand();
x = randn(1,1000);
lamda = rand();
for k = 2 : 1000
z(k)=lamda*x(k)+(1-lamda)*z(k-1);
end

1 comentario

Md. Tanjin Amin
Md. Tanjin Amin el 8 de Jul. de 2017
Hi, Thank you. Atually, I should have been more specific. X is 1000*22 matrix and initial value of Z is zero (a 1*22 zero matrix)..Can you help please?

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 8 de Jul. de 2017

Comentada:

el 10 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by