How to write y(n)=y(n-1)+x(n) in a way to store all values of y from n=1 to n?

5 ビュー (過去 30 日間)
Marwan Malaeb
Marwan Malaeb 2017 年 4 月 20 日
コメント済み: Marwan Malaeb 2017 年 4 月 20 日
How to write y(n)=y(n-1)+x(n) in a way to store all values of y from n=1 to n?

採用された回答

James Tursa
James Tursa 2017 年 4 月 20 日
編集済み: James Tursa 2017 年 4 月 20 日
There are vectorized ways to do this, but using your formula directly:
y = zeros(size(x));
y(1) = something; % <-- you fill this in, e.g. maybe x(1)?
n = something; % <-- you fill this in
for k=2:n % <-- for the rest of the elements through n
y(k) = y(k-1) + x(k); % <-- your formula
end
  2 件のコメント
Marwan Malaeb
Marwan Malaeb 2017 年 4 月 20 日
Thanks, I will try it and see if it works.
Marwan Malaeb
Marwan Malaeb 2017 年 4 月 20 日
It worked, thanks James

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by