Retrieve the time that a certain value is reached within a time series.

I am running a Simulink model and am changing constant to see how the system responds. I want to know what time the system reaches a certain value at each of the constants. I have same the time series to the work space but can not figure out how to extract the time at which the value becomes true.

 채택된 답변

goerk
goerk 2016년 1월 12일
A simple way is to extract the data and the time as arrays
% create example data
d=1:100;
t=d/100;
ts = timeseries(d,t);
% define threshold
thr = 55;
data = ts.data(:);
time = ts.time(:);
ind = find(data>thr,1,'first');
time(ind) %time where data>threshold

댓글 수: 3

I was able to seperate the data and the time into 2 different vectors but when I make 'ind' the answer is an empty 1x0 matrix.
>> speed=N.data(:); >> time=N.time(:); >> thr=max(N)
thr =
7.9999e+04
>> ind=find(speed>thr,1,'first')
ind =
Empty matrix: 0-by-1
Figured it out, the value i was looking for ended up being the max value so the vector never became greater than it so i needed to turn
ind = find(data>thr,1,'first');
to
ind = find(data=>thr,1,'first');
Thank you so much goerk. This answer is truly helpful!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Israel Vargas
Israel Vargas 2019년 1월 13일

1 개 추천

Hi, excelent way to find a value in vectors. I'm doing something similar. While I'm running the simulation (in real time) I would like to get the especific time when a diferent signal change to a especific value. I have tried to edit what your writed but with bad results. I suppose because the dimentions of the time and the voltage signals are changing while the simulation is running. Please help me!

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

제품

태그

질문:

2016년 1월 12일

답변:

2019년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by