Dynamic Array update without for loop

Dear All,
Is there any possibilty to run below mentioned code without using FOR loop as run time is higher with loops,
A=rand(100000,1);B=rand(100000,1);
Out=zeros(length(A),1);
for i=2:length(A)
Out(i)=0.1*Out(i-1)+(0.9*(A(i-1)-B(i)));
end

2 件のコメント

Walter Roberson
Walter Roberson 2019 年 7 月 22 日
I suspect that filter() or related functions could be used
Vick
Vick 2019 年 7 月 22 日
Hi Walter, Can you give some example code for this function. You are right that the function is a kind of transfer function. I don't know how to give the filter constant in this case is (0.1), taking from the pervious time and (1-0.1) taking from other calculation.

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

 採用された回答

Matt J
Matt J 2019 年 7 月 22 日
編集済み: Matt J 2019 年 7 月 22 日

0 投票

X=0.9*(A(1:end-1)-B(2:end));
Out=[0; filter(1,[1,-0.1],X)];

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

製品

タグ

タグが未入力です。

質問済み:

2019 年 7 月 22 日

編集済み:

2019 年 7 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by