finding the intersection for a trace to a threshold

조회 수: 5 (최근 30일)
Marco Avalos
Marco Avalos 2019년 10월 4일
댓글: Marco Avalos 2019년 10월 7일
Hi I am trying to find the points of intersection of a trace compared to a threshold. Let me explain, I have the trace of the movement of the foot in the z axis (raising the toe and putting it back to the floor in a step) and I want to find the points of intersection of a determined threshold (which is 5 mm above the minimum point of the swing of the toe). I have tried codes that I have found around but I need something according to my data
zstp=Rtoez(mRTO(i):mRHS(i));
t1M=find(islocalmax(nzstp,'MaxNumExtrema',1));
tmin=find(islocalmin(nzstp(t1M:end)))+t1M-1;
tclear=zstp(tmin);ntclear=nzstp(tmin);
traise=nzstp(t1M);
%% Determining the initial threshold
cutoff=round(ntclear+5)*ones(size(nzstp,1),1);
if cutoff > (ntclear+5)
cutoff=cutoff-1;
end
So now I need the intersects of nzstp to cutoff, so I can calculate the area under the threshold but above the curve
  댓글 수: 2
Marco Avalos
Marco Avalos 2019년 10월 4일
I only need this area no the area above the thresholduntitled.png

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

채택된 답변

Daniel M
Daniel M 2019년 10월 4일
편집: Daniel M 2019년 10월 4일
You can get the closest data points on either side of the threshold very easily.
location = threshold >= data;
% location is 1 below or on threshold, 0 above it
crossover = diff(location);
% crossover is -1 when it goes from below to above, 0 when it stays the same, and +1 when it goes from above to below.
Now use find() to look for instances of -1 and +1 within the variable crossover. (Note that the length of crossover will be one fewer than the length of location). If all you need is the closest index position, this is good enough. If you need a more precise answer, do a linear interpolation between the two closest points above and below at each crossing. How you choose to calculate area under the curve at that point is up to you.
Alternatively, you could do the following (this is probably even simpler).
newdata = min(data,threshold);
% then integrate to get the area, possibly with:
myarea = trapz(newdata);
But again, you haven't indicated anything about precision, so it's hard to give a very precise answer.
  댓글 수: 1
Marco Avalos
Marco Avalos 2019년 10월 7일
Thank, you this helps me a lot. Interpolating more points gave me the exactitude needed.

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

추가 답변 (1개)

Turlough Hughes
Turlough Hughes 2019년 10월 4일
I'm not sure which variable you use to represent your x data, but lets call it x, where x is the same size as nzstp and cutoff.
You can find your intersection points with this handy function polyxpoly as follows:
[xi, yi]=polyxpoly(x,nzstp, [x(1) x(end)],[cutoff(1) cutoff(end)]);
hold on; plot(xi,yi,'^k')
The inputs are your curve data and the start and end points for your threshold line which I have written as
x,nzstp % curve data
[x(1) x(end)],[cutoff(1) cutoff(end)] %start and end point of threshold line
Note you may need to download the mapping toolbox if you dont already have it installed in order to you polyxpoly.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by