Cycle counter with reset

조회 수: 5 (최근 30일)
Luccas S.
Luccas S. 2021년 12월 15일
댓글: Sargondjani 2021년 12월 18일
I apologize for not having developed any code for this part, because I have no idea how to do it. So, I'm going to work with the block diagram and what I've created so far.
I can't think of a way to do this:
Basically, when p_fix is ​​found it is to check if PE>p_fix every 5 cycles repeatedly until IC occurs. If PE>p_fix is ​​not respected during these 5 cycles, it is to evaluate 5 cycles again and again....
What has been programmed so far:
for n = 1:size(t,1)
if n>=4
X = [Ia(n-1,1) Ia(n-2,1) ; Ia(n-2,1) Ia(n-3,1)];
future = [Ia(n,1) ; Ia(n-1,1)];
C = X\future;
Ia_future(n,1) = C(1,1)*Ia(n,1)+C(2,1)*Ia(n-1,1);
PE(n,1)=Ia(n,1)+Ia_future(n,1);
p(n,1) = (1+0.2)*max(PE);
if PE(n,1)>p(n,1)
p_fix = p(n,1);
end
end
end

채택된 답변

Sargondjani
Sargondjani 2021년 12월 16일
you can use the function mod. For example:
if mod(n,5) == 0
or variants thereof.
  댓글 수: 2
Luccas S.
Luccas S. 2021년 12월 17일
I think it would be interesting to work with if (mod(n,5)==0) && (PE(n,1))>p_fix)
or is it not necessary?
Sargondjani
Sargondjani 2021년 12월 18일
Yes, think that's what you need. But my advice is to always check if an algoirthm does what you expect.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by