How to find out when a timeseries passes zero?

3 views (last 30 days)
Anton
Anton on 24 Oct 2022
Commented: Anton on 26 Oct 2022
mdl = 'model_241022.slx';
load_system(mdl);
simOut = sim(mdl,'SaveOutput','on',...
'OutputSaveName','yOut',...
'SaveTime','on',...
'TimeSaveName','tOut');
y = simOut.get("yOut"); % extracting timeseries from the model
time = simOut.get("tOut");
P_cb = y{1}.Values; % timeserie for cerebral blood pressure
F_cb = y{2}.Values; % timeserie for cerebral blood flow
R = y{3}.Values; % timeserie for vascular resistance
r = y{4}.Values; % timeserie for vascular radius
c = y{5}.Values; % timeserie for calcium concentration
P_ic = y{6}.Values; % timeserie for intracranial pressure
MeanPcb = mean(P_cb);
% define threshold
thr = 0;
data = F_cb;
ind = find(data<thr);
time(ind) %time where data<threshold
Hi, i have a this script, which is used to run a simulink model. The outputs of the model are all timeseries. For one of the timeseries I want to find out when the timeserie passes zero. I added the graphs below. I want to find at what time the second graph (cerebral blood flow) passes zero for the first time.
I thought I could do this with the last couple of lines, but then I get the error:
Error in Intracranial_pressure_simulink (line 38)
P_cb = y{1}.Values; % dataset for cerebral blood pressure
Undefined function 'lt' for input arguments of type 'timeseries'.
Error in Intracranial_pressure_simulink (line 54)
ind = find(data<thr);
Is this the wrong way to find this value or do I need to do something with the timeserie? I would appreciate the help!
  2 Comments
dpb
dpb on 24 Oct 2022
I "know nuthink!" about Simulink and ergo simOut, but it appears that each is returned as a cell array containing a timeseries object.
So, F_cb is the timeseries, and the data contained in it has to be dereferenced.
%data = F_cb; % don't need copies of same data
ind = find(F_cb.CerebralPressure<thr); % find the indices of the data variable
We can't see what the variable names inside the timeseries object are; I used "CerebralPressure" as a standin for whatever is the correct name. Show us what
F_cb.Properties.VariableNames
returns ans we'll know...see timetable and the links there on how to address variables in the object. Also be sure to check out the link at the top of the page "Functions" -- it has a comprehensive list of all the things that can be done with the object -- many of which will make your life much easier to do various further analyses.
Anton
Anton on 26 Oct 2022
I found a solution. In the configuration properties of scope blocks in Simulink I can log the data to arrays instead of timeseries. This way I can use the data the way I want. Your answer didn't exactly solve my problem, but got me thinking the right way. Thanks!

Sign in to comment.

Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!