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

问题描述 投票:0回答:1

我在Simulink(R2015b)中有一个信号对应于电源输出。信号是每隔1分钟的离散标量。我想每天在特定时间(例如00:00)计算信号在第一时间和最后一次超过某个阈值的前一天的时间(或索引,因为值以1分钟为间隔离散)。 )。

如果可能,除非有更简单的解决方案,否则我希望在Simulink功能块中实现此目标。

谢谢!

https://imgur.com/a/yzrDylD

matlab simulink
1个回答
0
投票

您可以为此使用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-');

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.