필터 지우기
필터 지우기

Help regarding For loop

조회 수: 1 (최근 30일)
Md. Tanjin Amin
Md. Tanjin Amin 2017년 7월 8일
댓글: Walter Roberson 2017년 7월 10일
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)

채택된 답변

Jan
Jan 2017년 7월 8일
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
Md. Tanjin Amin
Md. Tanjin Amin 2017년 7월 10일
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 2017년 7월 10일
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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 7월 8일
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
Md. Tanjin Amin
Md. Tanjin Amin 2017년 7월 8일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by