# Find a value when it meets two conditions

4 vues (au cours des 30 derniers jours)
Saad Alqahtani le 27 Juin 2021
Commenté : Saad Alqahtani le 1 Juil 2021
Hi,
I'm trying to find a specific value in an array when it meets two conditions (1- as soon as it occur the first time, 2- if its longer than 2 seconds), then, I want the code to stop and give me the length from the beginng to that value that mets both conditions. Here is my code:
t= (2*2048);
for i = 1:length (M)
if W = find ((M >=5) & i > t)
break
W = length(i);
end
end
Thanks in advance for the help.
##### 4 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
dpb le 27 Juin 2021
Again, is it from the first >V crossing for 2 seconds whether M is continuously > V or not, or must it be an unbroken 2 seconds of M>V lasting at a minum of 2 seconds?
Is it known the condition will be true at some point if the latter or might it not last that long?
OK, the sample rate is 2048 Hz, then the number of elements to reach 2 sec is 4096 but that would have to start after the initial trigger point.
Is it possible to have more than one pulse stream -- that is, could you have M>V but not 2 sec of duration but then another, later sequence in the same signal does meet the criterion?
On the assumption that there is only one pulse present, then something like
i1=find(M>V,1); % trigger
ie=find(M(i1:end)<V,1); % end after trigger
i2=i1+ie; % signal end
isOK=(ie>=t); % test if ON length meets minimum
A function written to do the above search could then return either the found values and the flag variable or, if the duration were too short, an empty result for the other value depending on the wanted usage.
Saad Alqahtani le 1 Juil 2021
Thanks. That helps, although I might need to modify it a bit.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by