필터 지우기
필터 지우기

How to extract data from an array

조회 수: 3 (최근 30일)
Peter Darrouj
Peter Darrouj 2022년 3월 11일
답변: Benjamin Thompson 2022년 3월 11일
Hello. I have a signal with over 10mil data points. Whenever my signal crosses a certain threshhold i want to extract x numbers of point before and x numbers of point after it hit the threshhold.
IsEvent = true;
peakthreshhold = 120;
for i = 1:1:length(sig)
if (sig(i) >= peakthreshhold && IsEvent)
signal= (sig(i-20000):1:sig(i+50000));
disp(signal)
IsEvent = false;
end
end
so basically i wanted to extract 20000 points before it hit sig(i) to 50000 after it hit sig(i), so i get a new array with 70000 points extracted from sig(i).
If i run it now, i get 15 points

채택된 답변

Benjamin Thompson
Benjamin Thompson 2022년 3월 11일
Use
signal= sig(i-20000:1:i+50000);
And you probably need checks in case i < 20000 or i > (end - 50000) as special cases.

추가 답변 (1개)

KSSV
KSSV 2022년 3월 11일
Let x be your signal and val be yout threshold.
val = 50000 ;
tol = 10^-3 ;
idx = find(abs(sig-val)<=tol) ; % this gives the index of your threshold
v1 = sig(1:idx) ;
v2 = sig(idx+1:end) ;
  댓글 수: 1
Peter Darrouj
Peter Darrouj 2022년 3월 11일
i changed
signal= (sig(i-20000):1:sig(i+50000));
to:
signal= sig((i-20000):(i+50000));
This seems to have fixed the problem.
I still need to test ur answer because it looks like an easier way, but i dont understand what you did.

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

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by