簡體   English   中英

計算第一個和最后一個值高於閾值的時間

[英]Calculating time of first and last value above threshold

我在 Simulink (R2015b) 中有一個與 Power output 對應的信號。 該信號是 1 分鍾間隔的離散標量。 每天在某個時間(即 00:00)我想計算前一天的時間(或索引,因為值在 1 分鍾間隔內是離散的),其中信號第一次和最后一次超過某個閾值(見圖)。

如果可能的話,我想在 Simulink function 塊中實現這一點,除非有更簡單的解決方案。

謝謝!

圖片

為此,您可以使用查找function。 我不知道這是否可以實現為 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-');

在此處輸入圖像描述

鑒於tsignalthreshold有你談論的數據,另一個選擇是:

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

這將為您提供時間t的第一個和最后一個值,其中signal>threshold ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM