How to only consider data after a series of time points

2 views (last 30 days)
I have a Force x Time graph, and I am trying to write a code to determine the time point when the Force drops below 0, on the condition that it has already decreased past threshold 1 value, then increased past threshold 2 value, then decreased past threshold 3 value. How can I ensure these criteria have been met before i look for my first 0 value using
F1 = find(F < 0.001, 1, 'first')
Thanks in advance

Answers (1)

Ridwan Alam
Ridwan Alam on 3 Dec 2019
Edited: Ridwan Alam on 3 Dec 2019
If I understood it right, you have threshold values T0(=0?),T1,T2,T3:
F0 = find(F(2:end)<T0 & F(1:end-1)>=T0) +1; % indices of F decreasing past T0
F1 = find(F(2:end)<T1 & F(1:end-1)>=T1) +1; % indices of F decreasing past T1
F2 = find(F(2:end)>=T2 & F(1:end-1)<T2) +1; % indices of F increasing above T2
F3 = find(F(2:end)<T3 & F(1:end-1)>=T3) +1; % indices of F decreasing past T3
if ~isempty(F1)
tempF2 = F2(F2>F1(1));
if ~isempty(tempF2)
tempF3 = F3(F3>tempF2(1));
if ~isempty(tempF3)
finalIndex = F0(find(F0>tempF3(1),1,'first'));
end
end
end
Hope it helps!
  1 Comment
Ridwan Alam
Ridwan Alam on 3 Dec 2019
Edited: Ridwan Alam on 3 Dec 2019
BW = mean(F(4000:5000))
T1 = BW*0.9
T2 = BW*1.2
T3 = BW*0.9
T0 = 0
% BW =
% 774.3022
% T1 =
% 696.8720
% T2 =
% 929.1626
% T3 =
% 696.8720
F0 = find(F(2:end)<T0 & F(1:end-1)>=T0) +1; % indices of F decreasing past T0
F1 = find(F(2:end)<T1 & F(1:end-1)>=T1) +1; % indices of F decreasing past T1
F2 = find(F(2:end)>=T2 & F(1:end-1)<T2) +1; % indices of F increasing above T2
F3 = find(F(2:end)<T3 & F(1:end-1)>=T3) +1; % indices of F decreasing past T3
if ~isempty(F1)
tempF2 = F2(F2>F1(1));
if ~isempty(tempF2)
tempF3 = F3(F3>tempF2(1));
if ~isempty(tempF3)
finalIndex = F0(find(F0>tempF3(1),1,'first'));
end
end
end
% finalIndex =
% 7372

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!