필터 지우기
필터 지우기

how to read previous data

조회 수: 4 (최근 30일)
Nurulhuda Ismail
Nurulhuda Ismail 2019년 5월 22일
댓글: Nurulhuda Ismail 2019년 5월 23일
Hi,
Assume that I have to use 'for loop' iterations, i = 1: n and I want to calculate a function called 'alpha' as shown below.
My problem is, how I am going to write the MATLAB code for this function especially how to extract the last 2 previous value of alpha (alpha_{i-2}?

채택된 답변

Raj
Raj 2019년 5월 23일
Define alpha in an array and use the previous two elements by suitable indexing in a 'for' loop. Something like this:
n=input('Enter value of n:');
alpha=zeros(n+1,1); % Initialize alpha. Since index cannot start from zero,start from 1 upto n+1 rows
alpha(1,1)=1;
alpha(2,1)=2;
d=rand(n-1,1); % Use your d here
b=rand(n-1,1); % Use your b here
for ii=3:n+1
alpha(ii,1)=(d(ii-2,1)*alpha(ii-1,1))-(b(ii-2,1)*alpha(ii-1,1)*alpha(ii-2,1));
end
Hope this helps!!
  댓글 수: 1
Nurulhuda Ismail
Nurulhuda Ismail 2019년 5월 23일
It works. Thank you very much Raj.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by