How to find the indices of a point on a curve

Hi I have a curve with one maximum,I need to find the indices of the the two 0.707 points. Thanks

답변 (3개)

dpb
dpb 2015년 10월 28일

0 개 추천

If you have the curve as computed points, see
doc interp1
Switch the normal X,Y meanings to interpolate with Y as the independent variable instead of X in this case. Also, NB: You'll need to do this in two separate calls, one with the values to the left and another with those to the right of the maximum as interp1 must have unique values for the interpolating function.
This will solve for the precise location; not necessarily integer. If you want the nearest index, then either a) round the above results or b) use
[~,ix]=min(abs(y-sqrt(2)/2*ymax));
Again you'll have to do the above piecewise accounting for the length of the subvectors in the returned indices as there's no guarantee the locations will be symmetric or the same on both sides except under very particular circumstances.

댓글 수: 3

Sorry but I don't understand your answer Thanks
dpb
dpb 2015년 10월 28일
Well, I don't know what form your data are in...
Hi My data is in the form of vector

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

Thorsten
Thorsten 2015년 10월 29일
편집: Thorsten 2015년 10월 29일

0 개 추천

If y is your curve, in general you will not have values that are exactly 0.707 of your maximum. So the idea is to use the 2 values that differ the least from the desired value 0.707*max(y):
[~, idx] = sort(abs(y-0.707*max(y)));
idx = idx(1:2);

댓글 수: 4

Thanks.Yes my curve is Y. I tried your suggestion but the results were not as my figure shows,may be because you use absolute value while I have plus &minus.Can we find the closest value to 0.707? Thanks
Thorsten
Thorsten 2015년 10월 29일
I can see no reason why the code should not work for this curve. The abs is important because else the smallest values would be negative values. What values do you get if you run the my code? Could you provide the data of the curve?
I have got 64 and 96
Thorsten
Thorsten 2015년 10월 29일
편집: Thorsten 2015년 10월 29일
I see. These are the index values into your x. So if you have
x = -90:0.5:90;
x707 = x(idx)
x([64 96])
ans =
-58.50 -42.50
Note that I figured out x=-90:0.5:90 by eye and trial and error from your plot. You have to use the actual values of x of course.

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

yousef Yousef
yousef Yousef 2015년 11월 5일

0 개 추천

clear all clc Angle=[5 10 20 60 180 190 195 300 305]; collision=[]; for i=1:length(Angle)-1 d=[]; targetValue = Angle(i); tolerance = 5; diff = abs(Angle-targetValue); tt=find(diff>0 & diff <= tolerance);
if ( tt>0) d=[d 2]; else d=[d 1]; end collision=[collision;d]; end

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

제품

질문:

2015년 10월 28일

댓글:

dpb
2015년 11월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by