how to read previous data
4 ビュー (過去 30 日間)
古いコメントを表示
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.![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220600/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/220600/image.png)
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}?
0 件のコメント
採用された回答
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!!
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!