How to calculate the whole time that my signal values is more than zero?

3 次查看(过去 30 天)
Hello,
I'm stuck in the middle of my model and im wondering how i can do one simple calculation.
On the picture below u can see my signal.
I try to find out how much time the signal is greather than zero? Im tring to do it with simulink blocks.
Can anyone help me with this? I will be very thankful !
Тhank you in advance!

采纳的回答

Wan Ji
Wan Ji 2021-8-18
编辑:Wan Ji 2021-8-18
If your signal array is A, and with a time array t the same size as A.
The total time the signal is greater than zero will be
A = A(:); t = t(:);
q = A>0;
dt =[0;diff(t)];
t_positive = sum(dt(q)) % total time the signal is greater than zero
  3 个评论
Krasimir Terziev
Krasimir Terziev 2021-8-18
编辑:Krasimir Terziev 2021-8-19
Hello,
Thanks for the fast answer. Тhis is not exactly what I was looking for but the code working fine when i take the scope data into the workspace. (btw the A array and t array are aways the same - they are the x and y in scope block).
I find what im missing.
1st my model is a phasor with max step size to 5 and simulation time to 24*60*60*7 (7 days).
in that case when i put my signal into enable subsystem with specific structure inside(shown in the picture below) its going well BUT instead of const = 1, it have to be the same as the max step size. So the const = 5 now and it calc. as the same your code above! Now nometter the what max step size i use, its the same answer!!!
Thank you very much for helping me !

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 General Applications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by