计算第一个和最后一个值高于阈值的时间

Calculating time of first and last value above threshold

我在 Simulink (R2015b) 中有一个信号对应于功率输出。该信号是一个以 1 分钟为间隔的离散标量。 每天在某个时间(即 00:00),我想计算前一天的时间(或指数,因为值在 1 分钟间隔内是离散的),其中信号第一次和最后一次超过某个阈值(见图片)。

除非有更简单的解决方案,否则我想尽可能在​​ Simulink 功能块中实现它。

谢谢!

您可以为此使用 find 函数。我不知道这是否可以作为Simulink功能块来实现,我对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-');

鉴于 tsignalthreshold 拥有您所说的数据,另一种选择是:

getfield(t(signal>threshold),{[1 sum(signal>threshold)]})

这将为您提供时间 t 的第一个和最后一个值,其中 signal>threshold...