How do I save a value from an iteration of a for loop?

1 回表示 (過去 30 日間)
curly133
curly133 2018 年 4 月 25 日
コメント済み: Star Strider 2018 年 4 月 25 日
I am trying to save the value of en from this Least Mean Square algorithm after each loop, but my attempt at it does not seem to be working. How can I fix this?
close;
clear;
clc;
load sig.mat; % loads variables x and y
N = 5; % filter length
u = .01; % learning rate
h = zeros(1, N);
hold = zeros(1,500);
for n = 1:500
if n-N < 1
xn = [x(n:-1:1); zeros(N-n, 1)];
else
xn = x(n:-1:n-N+1);
end
en = y(n) - h*xn;
hold = en; % Why is this not saving en after each iteration?
h = h + (u*en*xn)';
end

採用された回答

Star Strider
Star Strider 2018 年 4 月 25 日
First, rename the ‘hold’ variable to something that does not overshadow a MATLAB function. (I renamed it ‘env’.) Then, subscript it:
env = zeros(1,500);
. . .
en = y(n) - h*xn;
env(n) = en;
  2 件のコメント
curly133
curly133 2018 年 4 月 25 日
Thanks!
Star Strider
Star Strider 2018 年 4 月 25 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by