Find a value when it meets two conditions

조회 수: 13 (최근 30일)
Saad Alqahtani
Saad Alqahtani 2021년 6월 27일
댓글: Saad Alqahtani 2021년 7월 1일
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
dpb
dpb 2021년 6월 27일
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
Saad Alqahtani 2021년 7월 1일
Thanks. That helps, although I might need to modify it a bit.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by