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

조회 수: 1 (최근 30일)
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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by