フィルターのクリア

finding the intersection for a trace to a threshold

11 ビュー (過去 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 日
untitled.png
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.
  2 件のコメント
darova
darova 2019 年 10 月 4 日
I love polyxpoly
darova
darova 2019 年 10 月 4 日
Intersections do the same also

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by