finding the intersection for a trace to a threshold
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponse acceptée
Daniel M
le 4 Oct 2019
Modifié(e) : Daniel M
le 4 Oct 2019
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.
Plus de réponses (1)
Turlough Hughes
le 4 Oct 2019
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.
[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 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!