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

simulinktime 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.

Best Answer

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