Check if the condition happened in previous cycles

1 回表示 (過去 30 日間)
Luccas S.
Luccas S. 2021 年 12 月 29 日
編集済み: Torsten 2021 年 12 月 29 日
I'm trying to make a condition to analyze every 5 cycles, but I need the value of p_fix (threshold) not to exceed PE. As I did, it only analyzes when it reaches 5 cycles, but I needed to check if PE>p was respected until it reaches 5 cycles again and again.
if mod(n,5)==0 && PE(n-1,1)>p_fix
fprintf('Accuses IC\n')

採用された回答

Matt J
Matt J 2021 年 12 月 29 日
編集済み: Matt J 2021 年 12 月 29 日
Update a boolean flag to keep track of it.
flag=true; %initial state
for n=1:N
flag=flag & PE(n-1,1)>p_fix;
if mod(n,5)==0 && flag
fprintf('Accuses IC\n')
end
  5 件のコメント
Torsten
Torsten 2021 年 12 月 29 日
編集済み: Torsten 2021 年 12 月 29 日
You use
flag=(PE(0,1)>p_fix);
in your code. But PE(0,1) does not exist and p_fix is not initialized to a real number. So flag is not initialized to logical.
Luccas S.
Luccas S. 2021 年 12 月 29 日
OK, yes. Now it worked, thank you all

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by