[英]Calculating time of first and last value above threshold
I have a signal in Simulink (R2015b) that corresponds to a Power output.我在 Simulink (R2015b) 中有一个与 Power output 对应的信号。 The signal is a discrete scalar in 1 minute intervals.
该信号是 1 分钟间隔的离散标量。 Every day at a certain Time (ie 00:00) i want to calculate the times of the day before (or index since values are discrete in 1 min intervals) where the signal crossed a certain threshold for the first and last time (see image).
每天在某个时间(即 00:00)我想计算前一天的时间(或索引,因为值在 1 分钟间隔内是离散的),其中信号第一次和最后一次超过某个阈值(见图)。
I would like to implement this in a Simulink function block if possible unless there is a more simple solution.如果可能的话,我想在 Simulink function 块中实现这一点,除非有更简单的解决方案。
Thanks!谢谢!
You can use the find function for this.为此,您可以使用查找function。 I don't know if this can be implemented as a Simulink function block, I have no clue about Simulink:
我不知道这是否可以实现为 Simulink function 块,我对 Simulink 毫无头绪:
% fake some data
t = 0:200;
signal = 100*exp(-((t - 100)/50).^2) + randn(1,201)*10;
% plot signal
plot(t, signal);
threshold = 50;
% find first above threshold
ind1 = find(signal > threshold, 1, 'first');
% find last above threshold
ind2 = find(signal > threshold, 1, 'last');
% plot it
hold on;
plot([1 1] * t(ind1), [0 100], 'r-', [1 1] * t(ind2), [0 100], 'r-');
Given that t
, signal
and threshold
have the data you talk about, another option is:鉴于
t
, signal
和threshold
有你谈论的数据,另一个选择是:
getfield(t(signal>threshold),{[1 sum(signal>threshold)]})
this will give you the first and last values of time t
where signal>threshold
...这将为您提供时间
t
的第一个和最后一个值,其中signal>threshold
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.