필터 지우기
필터 지우기

Can this for-loop be vectorized?

조회 수: 2 (최근 30일)
Niek Blikslager
Niek Blikslager 2020년 11월 15일
댓글: Niek Blikslager 2020년 11월 15일
I want to find the moments of footfalls on a forceplate. I first find the peaks in the GRF, and all the valleys in between each step:
[~,locs]=findpeaks(f,'minpeakheight',1000,'minpeakdistance',50);
[~,locs2]=findpeaks(-f,'minpeakheight',-10);
Now I find the last valley before each peak, in order to determine when the force peak of a foot step starts.
for i = 2 : length(locs) - 1
steps(i-1) = max( locs2(locs2>locs(i-1) & locs2<locs(i)) );
end
Is it possible to change this loop into (short) vectorized code? I have to run this loop often, which takes time.
Thanks!

채택된 답변

Bruno Luong
Bruno Luong 2020년 11월 15일
편집: Bruno Luong 2020년 11월 15일
u = setdiff(locs2,locs);
% if locs2 is sorted and does not intersect with locs
% you can replace u by locs2
steps = interp1(u,u,locs(2:end-1),'previous')
  댓글 수: 1
Niek Blikslager
Niek Blikslager 2020년 11월 15일
Thank you! This is very usefull

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by