count the duration for which variable value is zero in simulink

t=(1:1:24); I=[0 0 0 1 1 1 2 2 2 5 5 5 10 10 10 15 15 15 5 5 5 0 0 0];
If these are the inputs in Simulink using a lookup
How can I determine the period for which the variabe (I) has the value of 0
Any help on this will be appreciated
Thanks.
regards Manish

댓글 수: 2

Do you need the duration that I=0 during the simulation, or after it has finished?
During the Simulation.

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

 채택된 답변

C.J. Harris
C.J. Harris 2012년 7월 23일

1 개 추천

I'd take the input and convert it into a logical signal (1's and 0's), inverse this signal using a NOT block. Convert this back to a number (again, 1's and 0's) and feed it through an integrator block. The integrator output will then increase by a factor of 1 each second the input is non-zero. This output will then equal the amount of time your signal was zero.

댓글 수: 4

This logic gives me the total number of instances when the value is zero. What I need is, the count should start when the variable Value is zero and reset the count when the variable value becomes nozero. Which means I need to determine the period for which the value is continuously zero.
Thanks would appreciate your inputs.
In this case add a reset condition to the integrator. Reset the integrator whenever it receives a non-zero value.
Thanks C.J.Harris it was really helpful. Just one last question will this logic be applicable if I want to check it for a variable value like 1 or 2 instead of zero?
Yes, you would need a slight modification though. Instead of converting the signal straight to a logical you would have to compare it against a constant.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

제품

질문:

2012년 7월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by