Determine begin and Endpoint of Interval with Threshold.
1 view (last 30 days)
Show older comments
I want to determine at which sample a curve in the movement of a player was started and at which sample the curve was stopped, to then calculate the magnitude of the total curve.
I have an input that shows the Index number of the midpoint of the curves(Mid_Angle(2x11 Matrix)). Around all these midpoints I want to know at which time the player started deviating his movement. Therefore, I have an Ang_Sample(1x1126), which displays the angle between the direction vectors of consecutieve samples.
I want to determine at which sample before the Midpoint of the angle the Ang_Sample went above 0.5 (and didn't go below 0.5 until MidPoint) to determine this as Beginpoint. And at which sample after the Midpoint the Ang_Sample went below 0.5 to determine this as Endpoint.
Right now I have a time interval (0.5s) which before and after I determine the first and last time to reach Ang_Sample above 0.5 . This method works well in most cases, but if the player makes an uncontrolled Angle or startes two angles shortly after each other I get problems.
d = 50 --> %number of samples interval before and after.
e = 0.5 --> %threshold for curve
for i= 1:length(Mid_Angle)
Ang_Abs = abs(Ang_Sample([Mid_Angle(1,i)-d]:[Mid_Angle(1,i)+d]));
Start_Ang(i) = find(Ang_Abs>e,1,'first')+(Mid_Angle(1,i)-d);
End_Ang(i) = find(Ang_Abs>e,1,'last')+(Mid_Angle(1,i)-d);
Total_Ang(i) = sum(Ang_Sample([Start_Ang(i)]:[End_Ang(i)]));
end
2 Comments
dpb
on 3 Mar 2014
Often the way to attack such is to convert the values to binary where
A(A>th)=1;
A(A<=th)=-1;
Then diff() and find the +/-2 locations
Image Analyst
on 3 Mar 2014
Attach data that illustrates the problem - something we can use to test code on. Also put in a plot or graph or something so we can visualize what's going on.
Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!