Help regarding For loop
1 回表示 (過去 30 日間)
古いコメントを表示
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)
0 件のコメント
採用された回答
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 件のコメント
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
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!